Swift assert

up:: Swift ⚐

If the condition fails, the app will crash and a message will be printed.

func sum(of numbers: [Int]) -> Int {
    assert(numbers.count > 0, "This should always be given some numbers to sum.")
    return numbers.reduce(0, +)
}

It is only used in Debug mode. In release mode, it gets compiled away.

assertionFailure will make the app crash whenever it is executed. Put it code that should never run, eg. the “default” state of a switch statement.i

assertionFailure("Failed to convert existing data to string")