转换为斯威夫特3(斯威夫特和火力地堡项目)

问题描述:

我刚刚更新了我的Xcode到Xcode8和我已经转换该项目以迅速3.转换为斯威夫特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中它有什么替代?

只需将其替换为: -

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

        } 
    }) 
+0

可以使用尾随符号。这使得阅读更简单。 '.signIn(withEmail:“dasd”,密码:“qwewqe”){...}'https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html#// apple_ref/doc/uid/TP40014097-CH11-ID102 – BennX

+0

太好了,谢谢你的提示!将检查链接。 – Mariah

+0

@玛利亚没有,这应该很好。@ BennX你到底想说什么?要使用'completionBlocks:'?哪里?这是预定义的Firebase身份验证功能。对不起,我只是没有得到你..请详细说明 – Dravidian