ERROR is value of type 'AuthDataResult' has no member 'uid'?

落爺英雄遲暮 提交于 2019-12-09 03:27:34

问题


My codes error I do not know why its saying that 'uid' has no member, also i don't know where AuthDataResult is coming from because i have never used this as an import or anything along those lines...

@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))
            }
    }
}
}

回答1:


The error you get is:

Value of type AuthDataResult has no member uid

If you look at the reference documentation for AuthDataResult, you'll see that this is correct: there is no uid in that class. The uid property exists in FIRUser, so you'll want to use:

user?.user.uid

Or to make it less confusing, give your current user variable a name that better matches what it is:

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))
    }
}


来源:https://stackoverflow.com/questions/51977775/error-is-value-of-type-authdataresult-has-no-member-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!