Latest 1.0.4
Homepage https://github.com/ivanbruel/DeltaCalculator
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

Version
License
Platform

DeltaCalculator

DeltaCalculator is a Swift Library focused on replacing reloadData() calls with animated insert, delete and move operations.

DeltaCalculator tries to optimize the number of iterations to calculate all the changes, making sure the UI thread doesn’t block.

This framework is based on BKDeltaCalculator Objective-C library.

Installation

DeltaCalculator is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'DeltaCalculator'

Usage

DeltaCalculator compares two arrays and computes the delta between them, represented by a Delta object.
DeltaCalculator is uses generics, therefor, you need to supply the class in the initializer.

In case your generic class is Equatable you can initialize the calculator without an equalityTest.

let deltaCalculator = DeltaCalculator<String>()
let delta = deltaCalculator.deltaFromOldArray(dataModel, toNewArray: newDataModel)

Otherwise you are required to supply an equalityTest in the initializer.

let deltaCalculator = DeltaCalculator<NSDate>() { (lhs, rhs) -> Bool in
  return lhs.compare(rhs) == .OrderedSame
}
let delta = deltaCalculator.deltaFromOldArray(dataModel, toNewArray: newDataModel)

UITableViews

To apply the Delta to a UITableView you need to use a batch update such as the following:

let delta = deltaCalculator.deltaFromOldArray(dataModel, toNewArray: newDataModel)
tableView.beginUpdates()
dataModel = newDataModel
delta.applyUpdatesToTableView(tableView, inSection: 0, withRowAnimation: UITableViewRowAnimation.Right)
tableView.endUpdates()

UICollectionViews

To apply the Delta to a UICollectionView you also need to perform it in a batch update:

let delta = deltaCalculator.deltaFromOldArray(dataModel, toNewArray: newDataModel)
collectionView.performBatchUpdates({
  self.dataModel = newDataModel
  delta.applyUpdatesToCollectionView(collectionView, inSection: 0)
}, completion: nil)

Sample

There is a sample project in the Example directory.

Author

Ivan Bruel, @ivanbruel

License

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

Latest podspec

{
    "name": "DeltaCalculator",
    "version": "1.0.4",
    "summary": "DeltaCalculator is a Swift Library focused on replacing reloadData() calls with animated insert, delete and move operations.",
    "description": "DeltaCalculator is a Swift Library focused on replacing reloadData()ncalls with animated insert, delete and move operations.nDeltaCalculator tries to optimize the number of iterations to calculate all the changes,nmaking sure the UI thread doesn't block.nThis framework is based on BKDeltaCalculator Objective-C library.",
    "homepage": "https://github.com/ivanbruel/DeltaCalculator",
    "license": "MIT",
    "authors": {
        "Ivan Bruel": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ivanbruel/DeltaCalculator.git",
        "tag": "1.0.4"
    },
    "social_media_url": "https://twitter.com/ivanbruel",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This