CustomDump Documentation

Structure Diff​Format

public struct DiffFormat  

Describes how to format a difference between two values when using diff(_:_:format:).

Typically one simply wants to use "-" to denote removals, "+" to denote additions, and " " for spacing. However, in some contexts, such as in XCTest failures, messages are displayed in a non-monospaced font. In those times the simple "-" and " " characters do not properly line up visually, and so you need to use different characters that visually look similar to "-" and " " but have the proper widths.

This type comes with two pre-configured formats that you will probably want to use for most situations: DiffFormat/default and DiffFormat/proportional.

Initializers

init(first:​second:​both:​)

public init(
    first: String,
    second: String,
    both: String
  )  

Properties

first

public var first: String

A string prepended to lines that only appear in the string representation of the first value, e.g. a "removal."

second

public var second: String

A string prepended to lines that only appear in the string representation of the second value, e.g. an "insertion."

both

public var both: String

A string prepended to lines that appear in the string representation of both values, e.g. something "unchanged."

`default`

public static let `default`  

The default format for diff(_:_:format:) output, appropriate for where monospaced fonts are used, e.g. console output.

Uses ascii characters for removals (hyphen "-"), insertions (plus "+"), and unchanged (space " ").

proportional

public static let proportional  

A diff format appropriate for where proportional (non-monospaced) fonts are used, e.g. Xcode's failure overlays.

Uses ascii plus ("+") for insertions, unicode minus sign ("−") for removals, and unicode figure space (" ") for unchanged. These three characters are more likely to render with equal widths in proportional fonts.