XCTUnwrap
Unwrap the value, or throw an error.
// โญโโโญ๏ธโโโฎ
func testUserToken() throws {
let user = User()
// if succeeds: get the value, if fails: throw an exception.
let token = try XCTUnwrap(user.getToken()) // โญ๏ธ can throw
XCTAssertEqual(token.count, 40)
}
func XCTUnwrap<T>(
_ expression: @autoclosure () throws -> T?,
_ message: @autoclosure () -> String = "",
file: StaticString = #filePath,
line: UInt = #line
) throws -> T
Last updated