转换为Swift 3(Swift和Firebase项目) [英] Converting to Swift 3 (Swift and Firebase Project)

查看:126
本文介绍了转换为Swift 3(Swift和Firebase项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在signIn函数中:

  Firth。在
中,如果发生错误=错误{},那么auth()?signIn(withEmail:self.EmailTF.text!,password:self.PasswordTF.text!,completion:{(user:FIRUser ?, error:NSError?)
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)

}
})

我得到这个错误:

 无法转换(FIRUser?,NSError?) - > ()'到期望的参数类型'FIRAuthResultCallback?'

在swift 3中替换它的方法是什么?

解决方案

只需将其替换为: code> FIRAuth.auth()?。signIn(withEmail:self.EmailTF.text!,password:self.PasswordTF.text!,completion:{$ user,err)
if 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)

}
})


I have just updated my Xcode to Xcode8 and I have converted the project to swift 3.

In signIn function here:

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

                        }
                    })

I'm getting this error:

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

What's the replacement of it in swift 3?

解决方案

Just replace it with :-

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

                    }
    })

这篇关于转换为Swift 3(Swift和Firebase项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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