2016-04-28 128 views
1

下面我刚才输入的错误是显示“无法覆盖类型值”(,) - > Void'to expected argument type'(NSERROR!) - > Void!)'Firebase创建用户swift不起作用

在这行代码

:?什么是错的

FIREBASE_REF.createUser(email, password: password, withCompletionBlock: {(error,authData) -> Void in 

@IBAction func creatAccountAction(sender: AnyObject) { 
     let email = self.emailTextField.text 
     let password = self.passwordTextField.text 

     if email != "" && password != "" 
     { 
      FIREBASE_REF.createUser(email, password: password, withCompletionBlock: {(error,authData) -> Void in 

      if error != nil { 

       FIREBASE_REF.authUser(email, password: password, withCompletionBlock: { (error, authData) -> Void in 

        if error == nil { 

         NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: "uid") 
        } 
        else { 
         print (error) 
        } 
       }) 
      } 
      else { 
       print (error) 
      } 

      } 

      )} 

     else 

回答

2

试试这个:

FIREBASE_REF.createUser(email, password: password, withCompletionBlock: {(error) -> Void in 

此块有可能只有一个参数

+0

非常感谢! – elciann

0

创建用户有两种选择,一种是创建用户,如果失败返回一个错误(withCompletionBlock),另一种选项返回authData(withValueCompletionBlock):这就是你想要的。

myRootRef.createUser(email, password: pw, withValueCompletionBlock: { error, result in 

      if error != nil { 
       print("error creating user") 
      } else { 
       let uid = result["uid"] as! String 
       NSUserDefaults.standardUserDefaults().setValue(uid, forKey: "uid") 
       //pass the parameters to another function to auth the user 
       self.authUserWithAuthData(email, password: pw) 
      } 

     })