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 to false.

    file

    The file name to print with the description of error if the assertion fails. The default is the file where assert(_: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 where assert(_: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 to false. The default is an empty string.

    file

    The file name to print with message if the assertion fails. The default is the file where assert(_:_: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 where assertionFailure(error:file:line:) is called.

    line

    The line number to print along with the description of error. The default is the line number where assertionFailure(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 where assertionFailure(_:file:line:) is called.

    line

    The line number to print along with message. The default is the line number where assertionFailure(_: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 where fatalError(_:file:line:) is called.

    line

    The line number to print with the description of error. The default is the line number where fatalError(_: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 where fatalError(_:file:line:) is called.

    line

    The line number to print along with message. The default is the line number where fatalError(_: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 to false.

    file

    The file name to print with the description of error if the precondition fails. The default is the file where precondition(_: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 where precondition(_: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 to false 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 where precondition(_:_:file:line:) is called.

    line

    The line number to print along with message if the precondition fails. The default is the line number where precondition(_:_: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 where preconditionFailure(error:file:line:) is called.

    line

    The line number to print along with the description of error. The default is the line number where preconditionFailure(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 where preconditionFailure(_:file:line:) is called.

    line

    The line number to print along with message. The default is the line number where preconditionFailure(_:file:line:) is called.