Indicates that an internal sanity check failed.
SDK
- Xcode 6.1+
Framework
- Swift Standard Library
Declaration
func assertionFailure(_ message: @autoclosure () -> String = String(), file: Static String = #file, line: UInt = #line)
Parameters
messageA string to print in a playground or
-Ononebuild. The default is an empty string.fileThe file name to print with
message. The default is the file whereassertionis called.Failure(_: file: line:) lineThe line number to print along with
message. The default is the line number whereassertionis called.Failure(_: file: line:)
Discussion
Use this function to stop the program, without impacting the performance of shipping code, when control flow is not expected to reach the call—for example, in the default case of a switch where you have knowledge that one of the other cases must be satisfied. To protect code from invalid usage in Release builds, see precondition.
In playgrounds and -Onone builds (the default for Xcode’s Debug configuration), stop program execution in a debuggable state after printing
message.In -O builds, has no effect.
In -Ounchecked builds, the optimizer may assume that this function is never called. Failure to satisfy that assumption is a serious programming error.