Skip to content

nerdishbynature/JSDiff.swift

Repository files navigation

JSDiff

Build Status codecov.io

A Swift wrapper around JsDiff.

Installation

Carthage is currently the only supported installation method:

github "nerdishbynature/JSDiff.swift"

Usage

Diffing words

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

added removed

License

See LICENSE file for more details