Functions
The following functions are available globally.
-
Performs a traditional C-style assert with an
Error
.Declaration
Swift
@inlinable public func assert(_ condition: @autoclosure () -> Bool, error: Error, file: StaticString = #file, line: UInt = #line)
Parameters
condition
The condition to test.
condition
is only evaluated in playgrounds and-Onone
builds.error
The error that represents the assertion failure when
condition
evaluates tofalse
.file
The file name to print with the description of
error
if the assertion fails. The default is the file whereassert(_:error:file:line:)
is called.line
The line number to print along with the description of
error
if the assertion fails. The default is the line number whereassert(_:error:file:line:)
is called. -
Performs a traditional C-style assert with an optional message.
Declaration
Swift
@inlinable public func assert(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line)
Parameters
condition
The condition to test.
condition
is only evaluated in playgrounds and-Onone
builds.message
A string to print if
condition
is evaluated tofalse
. The default is an empty string.file
The file name to print with
message
if the assertion fails. The default is the file whereassert(_:_:file:line:)
is called.line
The line number to print along with message if the assertion fails. The default is the line number where
assert(_:_:file:line:)
is called. -
Indicates that an internal sanity check failed.
Declaration
Swift
@inlinable public func assertionFailure(error: Error, file: StaticString = #file, line: UInt = #line)
Parameters
error
The error that represents the assertion failure.
file
The file name to print with the description of
error
. The default is the file whereassertionFailure(error:file:line:)
is called.line
The line number to print along with the description of
error
. The default is the line number whereassertionFailure(error:file:line:)
is called. -
Indicates that an internal sanity check failed.
Declaration
Swift
@inlinable public func assertionFailure(_ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line)
Parameters
message
A string to print in a playground or
-Onone
build. The default is an empty string.file
The file name to print with
message
. The default is the file whereassertionFailure(_:file:line:)
is called.line
The line number to print along with
message
. The default is the line number whereassertionFailure(_:file:line:)
is called. -
Unconditionally reports a given error and stops execution.
Declaration
Swift
@inlinable public func fatalError(_ error: Error, file: StaticString = #file, line: UInt = #line) -> Never
Parameters
error
The error to report.
file
The file name to print with the description of
error
. The default is the file wherefatalError(_:file:line:)
is called.line
The line number to print with the description of
error
. The default is the line number wherefatalError(_:file:line:)
is called. -
Unconditionally prints a given message and stops execution.
Declaration
Swift
@inlinable public func fatalError(_ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line) -> Never
Parameters
message
The string to print. The default is an empty string.
file
The file name to print with
message
. The default is the file wherefatalError(_:file:line:)
is called.line
The line number to print along with
message
. The default is the line number wherefatalError(_:file:line:)
is called. -
Checks a necessary condition for making forward progress.
Declaration
Swift
@inlinable public func precondition(_ condition: @autoclosure () -> Bool, error: Error, file: StaticString = #file, line: UInt = #line)
Parameters
condition
The condition to test.
condition is not evaluated in
-Ounchecked` builds.error
The error that represents the precondition failure when
condition
evaluates tofalse
.file
The file name to print with the description of
error
if the precondition fails. The default is the file whereprecondition(_:error:file:line:)
is called.line
The line number to print along with the description of
error
if the precondition fails. The default is the line number whereprecondition(_:error:file:line:)
is called. -
Checks a necessary condition for making forward progress.
Declaration
Swift
@inlinable public func precondition(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line)
Parameters
condition
The condition to test.
condition
is not evaluated in-Ounchecked
builds.message
A string to print if
condition
is evaluated tofalse
in a playground or-Onone
build. The default is an empty string.file
The file name to print with
message
if the precondition fails. The default is the file whereprecondition(_:_:file:line:)
is called.line
The line number to print along with
message
if the precondition fails. The default is the line number whereprecondition(_:_:file:line:)
is called. -
Indicates that a precondition was violated.
Declaration
Swift
@inlinable public func preconditionFailure(error: Error, file: StaticString = #file, line: UInt = #line) -> Never
Parameters
error
The error that represents the precondition failure.
file
The file name to print with the description of
error
. The default is the file wherepreconditionFailure(error:file:line:)
is called.line
The line number to print along with the description of
error
. The default is the line number wherepreconditionFailure(error:file:line:)
is called. -
Indicates that a precondition was violated.
Declaration
Swift
@inlinable public func preconditionFailure(_ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line) -> Never
Parameters
message
A string to print in a playground or
-Onone
build. The default is an empty string.file
The file name to print with
message
. The default is the file wherepreconditionFailure(_:file:line:)
is called.line
The line number to print along with
message
. The default is the line number wherepreconditionFailure(_:file:line:)
is called.