无法推断通用参数“T” - Swift 5.5

Art*_*uro 11 swift aws-amplify swiftui

我试图让用户登录,但收到以下错误:

Generic parameter 'T' could not be inferred
Run Code Online (Sandbox Code Playgroud)

这是代码:

// Gets User signed-in
func getUser() async throws -> AuthUser {
    do {
        try await withUnsafeThrowingContinuation { continuation in
            if let user = Amplify.Auth.getCurrentUser() {
                continuation.resume(returning: user )
            }
        }
    } catch(let error) {
        print(error)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是为什么?

Art*_*uro 12

实际上我的电话一开始就不好,应该这样做:

    // Gets User signed-in
    func getUser() async throws -> AuthUser {
        return try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<AuthUser, Error>) in
            if let user = Amplify.Auth.getCurrentUser() {
                continuation.resume(returning: user)
                return
            } else {
                signOut()
                continuation.resume(with: .failure(YourCustomEnumError_or_the_actual_error))
                return
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请访问此处

  • 在 `continuation in` 上指定返回类型,例如 `(continuation: CheckedContinuation&lt;YourUserModel, YourErrorType&gt;) in`... (2认同)