xcode 8中使用Swift 3的未知错误 - “源文件中的编辑器占位符”

xcode 8中使用Swift 3的未知错误 - “源文件中的编辑器占位符”

问题描述:

我创建了一个帮助函数来处理单击注册按钮时发生的情况。我试图连接Firebase数据库并使用我创建的参考输入输入的信息。我对你完成这项功能得到以下两个错误...xcode 8中使用Swift 3的未知错误 - “源文件中的编辑器占位符”

"Editor placeholder in source file" 
"Value of optional type 'String?' not unwrapped, did you mean '!' or '?'?" 

第一个错误是一个我最关心的问题,但所有指针将不胜感激。

这里是我创建处理RegisterButtonClick动作的功能:其中被称为误差

func handleRegisterClick(){ 
     guard let email = emailTextField.text, let password = passwordTextField.text, let name = nameTextField.text else{ 
      print("Form is not valid...") 
      return 
     } 

     FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user: FIRUser?, error) in 
      if error != nil{ 
       print(error ?? "user was not created... something went wrong") 
       return 
      } 
      // else... succesfully authernticated user 

      var ref: FIRDatabaseReference! 
      ref = FIRDatabase.database().reference() 

      let values = ["name": name, "email": email] 

      ref.updateChildValues(values, withCompletionBlock: { (err, ref) in 
       if err != nil{ 
        print(err ?? "Child values could not be updated... something went wrong") 
        return 
       } 
       print("Saved user successfully into the Firebase DB") 
      }) 
     }) 
     print("Register Button was pressed.") 
    } 

最多以上。下面的代码块显示了此功能被称为:

lazy var loginRegisterButton: UIButton = { 
     let button = UIButton(type: .system) 
     button.backgroundColor = UIColor(r: 80, g: 101, b: 161) 
     button.setTitle("Register", for: .normal) 
     button.setTitleColor(UIColor.white, for: .normal) 
     button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16) 

     button.addTarget(self, action: #selector(handleRegisterClick), for: .touchUpInside) 

     // this next step is needed or else the constraints set later on will not work 
     button.translatesAutoresizingMaskIntoConstraints = false 
     return button 
    }() 

固定的第一个错误的任何帮助将是非常有益的。我只是不明白错误在说什么。 iOS开发非常新,因此对任何不明显的道歉。

Xcode在使用自动完成时在您的代码中插入占位符。你应该用你自己的价值取代它们。第一个错误意味着您在代码中留下了其中一个占位符。它应该看起来不同,带有不同颜色的圆形“丸状”背景。找到并替换它或删除它。

第二误差意味着你有一个可选的字符串(String?),您有使用!?把它变成一个非可选String解开。

此:

(user: FIRUser?, error) 

应该

(user, error) 

这应该纠正这两个错误。如果没有,请指出可选错误发生在哪一行,我会更新答案。