A Swift wrapper around JsDiff.
Carthage is currently the only supported installation method:
github "nerdishbynature/JSDiff.swift"
Simply put your desired colors into the JSDiff
initializer where deletedColor
is the lighter color and deletedWordColor
is the one that should be more prominent (see the example image).
This method will result a JSLineDiff
which has 2 attributed strings containing the diff.
let oldLine = "... something"
let newLine = "..."
let jsDiff = JSDiff(deletedColor: UIColor.deletedColor(), deletedWordColor: UIColor.strongDeletedColor(), addedColor: UIColor.addedColor(), addedWordColor: UIColor.strongAddedColor())
let result = jsDiff.diffWords(oldLine, newLine: newLine)
oldLineLabel.attributedText = result.oldLine
newLineLabel.attributedText = result.newLine
See LICENSE file for more details