/DFDiff

Finds difference between two collections A and B (i.e. NSArrays) and create A -> B transformation consists of delete, insert and move operations only.

Primary LanguageObjective-CMIT LicenseMIT

DFDiff demo

Build status

This small and extremely simple Objective-C library might help you to find a set of simple operations (insert, delete, move) to transform one array into another i.e. @[A, B] -/diff/-> @[B, A], diff = [move(0, 1)]. Currently the library supports only single-dimensional arrays (NSArray). It also provides a convenient way to animate reloading data in UITableView 💣 .

DFDiff

How to use

First, all objects you want to store in arrays need to implement DFDiffId protocol where - (NSString *)diffId must be an unique string for every single item.

@interface DFArrayDiffDemoModelEntity : NSObject <DFDiffId>

To manage changes on UITableView you can use DFTableDataReloader. Create a new instance with reference to your table view

self.tableDataReloader = [DFTableDataReloader reloaderWithTableView:self.tableView];

and then pass new array whenever you need to refresh the table view (- (void)reloadData:(NSArray <id <DFDiffId>> *)items; )

[self.tableDataReloader reloadData:dataArray];

If something is not clear please take a look at 🚀 DemoApp.

Installation

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries.

Podfile

To integrate DFDiff into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '7.0'

target 'TargetName' do
pod 'DFDiff', '~> 0.1.0'
end

Problems?

Yup, sometimes happen ¯\(ツ)/¯ ☺ Please open a new Issue here if you run into a problem specific to DFDiff, have a feature request, or want to share a comment.

Pull requests are encouraged and greatly appreciated! 🍺

License

DFDiff is available under the MIT license. See the LICENSE file for more info.