“类型为'AuthDataResult'的值没有成员'uid'"错误 [英] "Value of type 'AuthDataResult' has no member 'uid'" error

查看:106
本文介绍了“类型为'AuthDataResult'的值没有成员'uid'"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决这个问题吗?第一个错误是类型为'authdataresult'的值没有成员'uid'".

Can someone help me about this issue? The first error was "value of type 'authdataresult' has no member 'uid'".

Auth.auth()?.signIn(withEmail: email, password: password, completion:

因此,我删除了问号以解决问题,并且该方法奏效了!但是在那之后,又出现了另一个错误,并说类型'AuthDataResult'的值没有成员'uid'".我知道,这很烦人.

So I removed the question mark to resolve the problem and it worked! But after that, another error came and it said "Value of type 'AuthDataResult' has no member 'uid'". I know, it's irritating.

self.userUid = user.uid

哦,还有另一个错误,它在我的项目中已经存在很长时间了,所以现在我忽略了它,但是如果有人知道如何修复它,请告诉我.错误是只能将实例方法声明为@ibaction".

And oh, there's another error and it's been in my project for a very long time so now i'm ignoring it but then if someone knows how to fix it please let me know. The error is "only instance methods can be declared @ibaction".

@IBAction func signInTapped(_ sender: Any) {

我不知道为什么,但是可能这3个错误有关.我不知道.帮助. 所以现在我又被卡住了.这是整个混乱的编码工作.

I don't know why but maybe the 3 errors are connected. I don't know. Help. So now I'm stuck again. Here is the whole messed up coding stuff.

import UIKit
import Firebase

class ViewController: UIViewController {
    @IBOutlet weak var emailField: UITextField!
    @IBOutlet weak var passwordField: UITextField!

    var userUid: String!

    func goToCreateUserVC(){
        performSegue(withIdentifier: "SignUp", sender: nil)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "SignUp" {
            if let destination = segue.destination as? userVC {
                if userUid != nil {
                    destination.userUid = userUid
                }
                if emailField.text != nil {
                    destination.emailField = emailField.text
                }
                if passwordField.text != nil {
                    destination.passwordField = passwordField.text
                }
            }
        }

        @IBAction func signInTapped(_ sender: Any) {
            if let email = emailField.text, let password = passwordField.text {
                Auth.auth().signIn(withEmail: email, password: password, completion: { (user,error) in
                    if error == nil {
                        if let user = user {
                            self.userUid = user.uid
                            self.goToCreateUserVC()
                        }
                    } else {
                        self.goToCreateUserVC()
                    }
                });
            }
        }
    }
}

就像我发誓一样,我尝试修复它,然后弹出了9个错误.顺便说一句,我正在使用Xcode 9,Swift 4,并且我的Cocoapods是最新的.对于所有编辑,评论或判断问题的人来说,这不是重复的问题.它们是2种不同的错误.

Like I swear, I tried to fix it and then 9 errors just popped out. By the way, I'm using Xcode 9, Swift 4, and my Cocoapods are up-to-date. To those all around people who edit, comment, or judge questions, please this is not a duplicate question. They are 2 different errors.

推荐答案

Google似乎已通过5.0.0更新对Firebase Auth进行了一些更改. 这对我有用:

It seems that Google has made some changes to Firebase Auth with the 5.0.0 update. This worked for me:

self.userUid = user.user.uid

我不确定更改的目的是什么,但它的工作原理仍然完全相同.

I'm not sure what was the point of the change but it still works exactly the same.

这篇关于“类型为'AuthDataResult'的值没有成员'uid'"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆