键入“用户?"没有成员UID(Swift 3,Firebase) [英] Type "user?" had no member UID (Swift 3, Firebase)

查看:64
本文介绍了键入“用户?"没有成员UID(Swift 3,Firebase)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase设置登录页面,但遇到了无法识别uid的错误.这是我的代码:

I am setting up a login page with Firebase and I've run into an error where uid isn't getting recognized. Here's my code:

    FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (FIRUser,error) in

        if error != nil {
            print(error)
            return

        }

        guard let uid = user?.uid else {
            return
        }

我也无法命令点击进入FIRUser,但是,如果我摆脱了保护声明,那么身份验证就可以正常工作.

I also can't command-click into FIRUser, however if I get rid of the guard statement, authentication works perfectly fine.

我已经导入了Firebase和FirebaseDatabase(无法导入FirebaseAuth,它被划掉了),所以不是那样.

I have Firebase and FirebaseDatabase imported (can't import FirebaseAuth, it's crossed out), so it's not that.

有人知道为什么我无法访问FIRUser并使用uid吗?

Any idea why I can't access FIRUser and use uid?

推荐答案

您需要在闭包内部创建变量user.改成您的函数.

You need to create the variable user inside your closure. Rewrite your function to this instead.

FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user: FIRUser?, error: Error?) in

    if error != nil {
        print(error)
        return

    }

    guard let uid = user?.uid else {
        return
    }

这篇关于键入“用户?"没有成员UID(Swift 3,Firebase)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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