2016-04-28 126 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) 
      } 

     })