Generic Function

XCTUnwrap(_:_:file:line:)

Asserts that an expression is not nil and returns the unwrapped value.

Declaration

func XCTUnwrap<T>(_ expression: @autoclosure () throws -> T?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) throws -> T

Parameters

expression

An expression of type T?. The expression’s type determines the type of the return value.

message

An optional description of the failure.

file

The file in which the failure occurred. The default is the file name of the test case in which this function was called.

line

The line number on which the failure occurred. The default is the line number on which this function was called.

Return Value

The result of evaluating and unwrapping the given expression, which is of type T. XCTUnwrap() only returns a value if expression is not nil.

Discussion

This function generates a failure when expression is nil. Otherwise, it returns the unwrapped value of expression for subsequent use in the test.

See Also

Testing if a Condition is Non-nil