Diffing 0.5.0

Diffing 0.5.0

WillMcGinty维护。



Diffing 0.5.0

  • 作者:
  • William McGinty

Diffing

CI Status Version Platform

Diffing是一个小型框架,旨在尽可能快速和简单地将任何两个集合之间的差异或编辑识别出来。它是保罗·赫克尔算法的实现,Diffing通过在两个集合上执行五次遍历来识别给定sourcedestination集合之间的差异,并以易于理解和应用的方式输出,例如在UITableviewUICollectionView等UI元素上。

例如,给出以下两个集合

let old = [1, 2, 3, 4, 5]
let new = [1, 2, 3, 4, 5, 6]

使用对Collection的简单扩展来确定差异

let difference = old.difference(to: new)
difference.sortedChanges // [.insert(value: 6, index: 5)]

此外,difference集合中的更改也可以应用于任何任意集合。在这种情况下,将这些更改应用到old上始终会产生new

let equals = old.applying(difference: difference) == new // true

灵感

Diffing深受类似框架如卓越的IGListKit的影响。保罗·赫克尔发布的最原始算法发布在这里

要求

需要iOS 10.0,tvOS 10.0,macOS 10.12

安装

Cocoapods

差分功能可通过CocoaPods访问。要安装,只需将以下行添加到您的Podfile

pod 'Diffing'

Carthage

将以下内容添加到您的Cartfile

github "wmcginty/Diffing"

运行carthage update,并按照CarthageREADME中描述的步骤进行操作。

Swift Package Manager

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