【问题标题】:ERROR is value of type 'AuthDataResult' has no member 'uid'?错误是“AuthDataResult”类型的值没有成员“uid”?
【发布时间】:2018-08-23 03:04:12
【问题描述】:

My codes error 我不知道为什么它说 'uid' 没有成员,我也不知道 AuthDataResult 来自哪里,因为我从未将其用作导入或任何类似的东西......

@IBAction func signinPressed(_ sender: Any) {
    if let email = emailField.text, let password = passwordField.text {
        Auth.auth().signIn(withEmail: email, password: password) { (user, error )
        in
            if error != nil{
                //create account
            } else {

                KeychainWrapper.standard.set((user?.uid)!,
                forKey: ("Key_UID"))
                self.preformSegue(performSegue(withIdentifier: "toFeed", sender: nil))
            }
    }
}
}

【问题讨论】:

    标签: swift firebase firebase-authentication


    【解决方案1】:

    你得到的错误是:

    AuthDataResult 类型的值没有成员 uid

    如果您查看reference documentation for AuthDataResult,您会发现这是正确的:该类中没有uiduid 属性存在于 FIRUser 中,因此您需要使用:

    user?.user.uid
    

    或者为了减少混淆,给你当前的user变量取一个更匹配它的名字:

    Auth.auth().signIn(withEmail: email, password: password) { (authData, error ) in
        if error != nil{
            //create account
        } else {
    
            KeychainWrapper.standard.set((authData?.user.uid)!,
            forKey: ("Key_UID"))
            self.preformSegue(performSegue(withIdentifier: "toFeed", sender: nil))
        }
    }
    

    【讨论】:

    • 我很困惑我有 var: user: String! , 和 user?.user?.uid 现在在我的代码中,我收到一条错误消息 (Cannot use optional chaining on non-optional value of type 'User')
    • 啊,原来userAuthData 中是非可选的。我更新了代码。
    • 谢谢你这个概念对我来说很奇怪,因为它就像你在输入实际代码时将错误推开,对我来说很奇怪可能是因为我是新手,但谢谢你弗兰克你是一个伟大的人!
    猜你喜欢
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    相关资源
    最近更新 更多