Diffing is a small framework that is desgined to make identifying the differences, or edits, between any two collections as quick and simple as possible. An implementation of Paul Heckel's algorithm, Diffing
uses a series of five passes over two collections to identify the differences between a given source
and destination
collection and output them in a way that is both easy to understand, and easy to apply to UI elements like UITableview
and UICollectionView
.
For example, given the following two collections:
let old = [1, 2, 3, 4, 5]
let new = [1, 2, 3, 4, 5, 6]
A simple extension on Collection
can be invoked to determine the differences:
let difference = old.difference(to: new)
difference.sortedChanges // [.insert(value: 6, index: 5)]
In addition, the set of changes in difference
can also be applied to any arbitrary collection. Applying this set of changes to old
in this case, will always produce new
.
let equals = old.applying(difference: difference) == new // true
Diffing is heavily inspired by similar frameworks like the incredible IGListKit. The original algorithm published by Paul Heckel is available here.
Requires iOS 10.0, tvOS 10.0, macOS 10.12
Diffing is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Diffing'
Add the following to your Cartfile:
github "wmcginty/Diffing"
Run carthage update
and follow the steps as described in Carthage's README.
dependencies: [
.package(url: "https://github.com/wmcginty/Diffing.git", from: "0.4.0")
]