precondition

func precondition(_: @autoclosure () -> Bool, _: @autoclosure () -> String, file: StaticString, line: UWord)

Check a necessary condition for making forward progress.

Use this function to detect conditions that must prevent the program from proceeding even in shipping code.

  • In playgrounds and -Onone builds (the default for Xcode's Debug configuration): if condition evaluates to false, stop program execution in a debuggable state after printing message.

  • In -O builds (the default for Xcode's Release configuration): if condition evaluates to false, stop program execution.

  • In -Ounchecked builds, condition is not evaluated, but the optimizer may assume that it would evaluate to true. Failure to satisfy that assumption in -Ounchecked builds is a serious programming error.

Declaration

func precondition(condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = default, file: StaticString = default, line: UWord = default)