Swiftpack.co - Package - krzysztofzablocki/Difference
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

Version License Platform


Better way to identify what's different between 2 instances.

Have you ever written tests? Usually they use equality asserts, e.g. XCTAssertEqual, what happens if the objects aren't equal? Xcode throws a wall of text at you:

This forces you to manually scan the text and try to figure out exactly whats wrong, what if instead you could just learn which property is different?



Add pod 'Difference' to your Podfile.


Add github "krzysztofzablocki/Difference" to your Cartfile.


Add .package(name: "Difference", url: "https://github.com/krzysztofzablocki/Difference.git", .branch("master")), dependency in your Package manifest.

Using lldb

Just write the following to see the difference between 2 instances:

po dumpDiff(expected, received)

Integrate with XCTest

Just add this to your test target:

public func XCTAssertEqual<T: Equatable>(_ expected: T, _ received: T, file: StaticString = #file, line: UInt = #line) {
    XCTAssertTrue(expected == received, "Found difference for \n" + diff(expected, received).joined(separator: ", "), file: file, line: line)

Replace #file with #filePath if you're using Xcode 12+.

Integrate with Quick

Just add this to your test target:

public func equalDiff<T: Equatable>(_ expectedValue: T?) -> Predicate<T> {
    return Predicate.define { actualExpression in
        let receivedValue = try actualExpression.evaluate()

        if receivedValue == nil {
            var message = ExpectationMessage.fail("")
            if let expectedValue = expectedValue {
                message = ExpectationMessage.expectedCustomValueTo("equal <\(expectedValue)>", "nil")
            return PredicateResult(status: .fail, message: message)
        if expectedValue == nil {
            return PredicateResult(status: .fail, message: ExpectationMessage.fail("").appendedBeNilHint())

        return PredicateResult(bool: receivedValue == expectedValue, message: ExpectationMessage.fail("Found difference for " + diff(expectedValue, receivedValue).joined(separator: ", ")))


Stars: 798


0.5.0 - 2020-10-13T10:09:40

Use full version specing for spm integration

Swift 5 update - 2020-08-03T09:45:42

0.4 - 2020-07-03T16:19:47


  • Proper support for unordered collections (Dictionaries/Sets)
  • Updated styling for indentation
  • Complete internal rewrite

- 2017-10-27T15:30:30

- 2017-10-18T16:27:25