Indicates that a precondition was violated.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
func preconditionFailure(_ message: @autoclosure () -> String = String(), file: Static String = #file, line: UInt = #line) -> Never
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 wherepreconditionis called.Failure(_: file: line:) lineThe line number to print along with
message. The default is the line number wherepreconditionis called.Failure(_: file: line:)
Discussion
Use this function to stop the program when control flow can only reach the call if your API was improperly used. This function’s effects vary depending on the build flag used:
In playgrounds and
-Ononebuilds (the default for Xcode’s Debug configuration), stops program execution in a debuggable state after printingmessage.In
-Obuilds (the default for Xcode’s Release configuration), stops program execution.In
-Ouncheckedbuilds, the optimizer may assume that this function is never called. Failure to satisfy that assumption is a serious programming error.