Skip to content
Swift port of IGListKit's IGListDiff
Branch: master
Clone or download
lxcid Merge pull request #9 from iBenjamin/master
Remove swift version in podspec
Latest commit 07e92e0 Apr 15, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
ListDiff.xcodeproj #6: Add stress tests of continous random collection view updates Aug 23, 2018
ListDiff Add support for Carthage Oct 9, 2017
Sources #6: Add missing code for making diff result suitable for UICollection… Aug 23, 2018
Tests Reduce iteration counts Oct 7, 2018
LICENSE Add podspec. Oct 26, 2016
ListDiff.podspec.json Remove swift version in podspec Apr 15, 2019
Package.swift Initial commit Oct 22, 2016 Adds cocoapods badge Oct 7, 2018

Build Status CocoaPods Compatible


ListDiff is a Swift port of IGListKit's IGListDiff. It is an implementation of an algorithm by Paul Heckel that calculates the diff between 2 arrays.


The motivation for this project came from the following challenge which I learnt about it from Ryan Nystrom's talk at iOSConf.SG.

Getting Started

swift package generate-xcodeproj



pod 'ListDiff'


github "lxcid/ListDiff" "master"


import ListDiff

extension Int : Diffable {
    public var diffIdentifier: AnyHashable {
        return self
let o = [0, 1, 2]
let n = [2, 1, 3]
let result = List.diffing(oldArray: o, newArray: n)
// result.hasChanges == true
// result.deletes == IndexSet(integer: 0)
// result.inserts == IndexSet(integer: 2)
// result.moves == [List.MoveIndex(from: 2, to: 0), List.MoveIndex(from: 1, to: 1)]
// result.changeCount == 4


During the port, I made several decisions which I would like to rationalize here.

  • Using caseless enum as namespace. See Erica Sadun's post here.
  • No support for index paths. Decided that this is out of the scope.
  • Stack vs Heap. AFAIK, Swift does not advocates thinking about stack vs heap allocation model, leaving the optimization decisions to compiler instead. Nevertheless, some of the guideline do favour struct more, so only List.Entry is a (final) class as we need reference to its instances.


You can’t perform that action at this time.