XCTUnwrap
// ╭──⭐️──╮
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 -> TLast updated
Was this helpful?