Skip to content

A simple implementation of Heckel's diffing algorithm in Swift

License

Notifications You must be signed in to change notification settings

wmcginty/Diffing

Repository files navigation

Diffing

CI Status Version Platform

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

Inspiration

Diffing is heavily inspired by similar frameworks like the incredible IGListKit. The original algorithm published by Paul Heckel is available here.

Requirements

Requires iOS 10.0, tvOS 10.0, macOS 10.12

Installation

Cocoapods

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

pod 'Diffing'

Carthage

Add the following to your Cartfile:

github "wmcginty/Diffing"

Run carthage update and follow the steps as described in Carthage's README.

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/wmcginty/Diffing.git", from: "0.4.0")
]

About

A simple implementation of Heckel's diffing algorithm in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published