soffes / Diff
Licence: mit
Simple diff library in pure Swift
Stars: ✭ 110
Programming Languages
swift
15916 projects
Projects that are alternatives of or similar to Diff
Functionkit
A framework for functional types and operations designed to fit naturally into Swift.
Stars: ✭ 302 (+174.55%)
Mutual labels: tvos, watchos, carthage
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+9632.73%)
Mutual labels: tvos, watchos, carthage
Rome
Carthage cache for S3, Minio, Ceph, Google Storage, Artifactory and many others
Stars: ✭ 724 (+558.18%)
Mutual labels: tvos, watchos, carthage
Web3.swift
A pure swift Ethereum Web3 library
Stars: ✭ 295 (+168.18%)
Mutual labels: tvos, watchos, carthage
Json
Micro framework for easily parsing JSON in Swift with rich error messages in less than 100 lines of code
Stars: ✭ 395 (+259.09%)
Mutual labels: tvos, watchos, carthage
Mixpanel
Unofficial Swift Mixpanel client
Stars: ✭ 93 (-15.45%)
Mutual labels: tvos, watchos, carthage
Guitar
A Cross-Platform String and Regular Expression Library written in Swift.
Stars: ✭ 641 (+482.73%)
Mutual labels: tvos, watchos, carthage
Swiftlinkpreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
Stars: ✭ 1,216 (+1005.45%)
Mutual labels: tvos, watchos, carthage
Queuer
Queuer is a queue manager, built on top of OperationQueue and Dispatch (aka GCD).
Stars: ✭ 964 (+776.36%)
Mutual labels: tvos, watchos, carthage
X
Easier cross platform Mac & iOS development with Swift
Stars: ✭ 270 (+145.45%)
Mutual labels: tvos, watchos, carthage
Sdwebimagewebpcoder
A WebP coder plugin for SDWebImage, use libwebp
Stars: ✭ 101 (-8.18%)
Mutual labels: tvos, watchos, carthage
Datez
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
Stars: ✭ 254 (+130.91%)
Mutual labels: tvos, watchos, carthage
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+3272.73%)
Mutual labels: tvos, watchos, carthage
TermiNetwork
🌏 A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications.
Stars: ✭ 80 (-27.27%)
Mutual labels: tvos, watchos, carthage
SwiftVer
Easily Manage Versioning in MacOS, iOS, watchOS, and tvOS projects.
Stars: ✭ 23 (-79.09%)
Mutual labels: tvos, watchos, carthage
Swiftframeworktemplate
A template for new Swift iOS / macOS / tvOS / watchOS Framework project ready with travis-ci, cocoapods, Carthage, SwiftPM and a Readme file
Stars: ✭ 527 (+379.09%)
Mutual labels: tvos, watchos, carthage
Ratelimit
Simple utility for only executing code every so often.
Stars: ✭ 918 (+734.55%)
Mutual labels: tvos, watchos, carthage
Diff
Simple diffing library in pure Swift.
Installing
You can use Carthage or Swift Package Manager to install Diff.
Usage
Start by importing the package:
import Diff
Same
If there is no difference, the diff will be nil
.
diff("Hello", "Hello") // nil
For the sake of brevity, we'll !
the rest of the examples since we know they're different.
Insert
let (range, string) = diff("Hello world", "Hello there world")!
// range: 6..<6
// string: "there "
Remove
let (range, string) = diff("Hello there world", "Hello world")!
// range: 6..<12
// string: ""
Other Types
Diff can diff any array. Here's an array of things that conform to Equatable
:
let (range, replacement) = diff([1, 2, 3], [1, 2, 3, 4])!
// range: 3..<3
// replacement: [4]
You can even use arrays of anything as long as you can compare them:
let before: [Foo] = [a, b]
let after: [Foo] = [b]
let (range, replacement) = diff(before, after, compare: Foo.compare)!
// range: 0..<1
// replacement: []
Development
If you want to contribute to Diff, please write a test.
Building and running the tests locally with SPM is easy:
$ git clone https://github.com/soffes/Diff
$ cd Diff
$ swift build
$ swift test
Thanks
Thanks to Jonathan Clem for the original algorithm and Caleb Davenport for inspiration for the generics implementation and help debugging a few edge cases!
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].