Swiftpack.co -  lxcid/ListDiff as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Swift port of IGListKit's IGListDiff
.package(url: "https://github.com/lxcid/ListDiff.git", from: "0.2.0")

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.



Stars: 227
Last commit: 1 year ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Related Packages

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API