【问题标题】:Converting to Swift 3 (Swift and Firebase Project)转换为 Swift 3(Swift 和 Firebase 项目)
【发布时间】:2016-09-18 20:52:51
【问题描述】:

我刚刚将我的 Xcode 更新为 Xcode8,并将项目转换为 swift 3。

在此处输入登录功能:

  Firth. Auth()?.signIn(withEmail: self.EmailTF.text!, password: self.PasswordTF.text!, completion: { (user: FIRUser?, error: NSError?) in
                        if let error = error {
                            print(error.localizedDescription)
                        } else {

                           self.ref.child("UserProfile").child(user!.uid).setValue([
                                "email": self.EmailTF.text!,
                                "name" : self.NameTF.text!,
                                "phone": self.PhoneTF.text!,
                                "city" : self.CityTF.text!,
                                ])
                            print("Sucess")

                        }
                    })

我收到此错误:

cannot convert value of type '(FIRUser?, NSError?) -> ()' to expected argument type 'FIRAuthResultCallback?'

swift 3 中的替换是什么?

【问题讨论】:

    标签: ios swift firebase firebase-authentication swift3


    【解决方案1】:

    只需将其替换为:-

     FIRAuth.auth()?.signIn(withEmail:self.EmailTF.text!, password: self.PasswordTF.text!, completion: { (user, err) in
           if let error = err {
                            print(error.localizedDescription)
                        } else {
    
                           self.ref.child("UserProfile").child(user!.uid).setValue([
                                "email": self.EmailTF.text!,
                                "name" : self.NameTF.text!,
                                "phone": self.PhoneTF.text!,
                                "city" : self.CityTF.text!,
                                ])
                            print("Sucess")
    
                        }
        })
    

    【讨论】:

    • 可以使用尾随表示法。这使它更易于阅读。 .signIn(withEmail: "dasd", password: "qwewqe"){...}developer.apple.com/library/content/documentation/Swift/…
    • 太好了,感谢您的来信!将检查链接。
    • @Mariah 不,这应该可以正常工作。@BennX 你到底想在这里说什么?要使用completionBlocks:?在哪里?这是一个预定义的 Firebase 身份验证功能。对不起,我只是没有得到你..请详细说明
    • 刚刚检查过,它对我来说工作正常。如果您要检查 textField 是否为空,请尝试name.text != ""
    猜你喜欢
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多