【问题标题】:Value of type 'AuthDataResult' has no member 'uid' problem'AuthDataResult' 类型的值没有成员 'uid' 问题
【发布时间】:2020-11-29 22:32:26
【问题描述】:

我是 Swift 的新手,正在学习如何在 youtube 上遵循 Kasey Schlaudt 的教程构建社交媒体应用程序。当我在分钟 36:11 写此行 KeychainWrapper.standard.set((user?.uid)!, forKey: "KEY_UID") 时,如果此视频:https://youtu.be/gBB5tnAzjjo?t=2171 我收到此错误 ->“AuthDataResult”类型的值没有成员“uid”。关于为什么会发生这种情况的任何建议? 到目前为止,这是我的代码:

import UIKit
import Firebase
import SwiftKeychainWrapper

class ViewController: UIViewController {
    
    @IBOutlet weak var UserImageView: UIButton!
    @IBOutlet weak var usernameField: UITextField!
    @IBOutlet weak var emailField: UITextField!
    @IBOutlet weak var passwordField: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    @IBAction func signInPress(_ sender: Any) {
        if let email = emailField.text, let password = passwordField.text {
            
            Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
                if error != nil {
                    //Create account
                } else {
                    KeychainWrapper.standard.set((user?.uid)!, forKey: "KEY_UID")
                }
        }
    }

    }

}

任何帮助将不胜感激!

【问题讨论】:

    标签: ios swift firebase firebase-authentication


    【解决方案1】:

    createUser 的 API 文档说它提供了一个 AuthDataResult 对象作为结果。正如您从链接中看到的那样,它没有 uid 属性。您将需要使用它的user 属性来获取一个具有uidUser 对象。

    Auth.auth().createUser(withEmail: email, password: password) { (result, error) in
        if error != nil {
            //Create account
        } else {
            KeychainWrapper.standard.set((result?.user.uid)!, forKey: "KEY_UID")
        }
    }
    

    【讨论】:

    • 赞成链接到产品的文档,这比 3 年前的 youtube 教程更可能是最新的。 ?
    猜你喜欢
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    相关资源
    最近更新 更多