ios - 在 xcode 8 中使用 Swift 3 出现未知错误 - "Editor placeholder in source file"

标签 ios swift firebase firebase-realtime-database firebase-authentication

我正在创建一个辅助函数来处理单击注册按钮时发生的情况。我正在尝试连接 Firebase 数据库并使用我创建的引用来输入输入的信息。完成该功能后出现以下两个错误...

"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

关于ios - 在 xcode 8 中使用 Swift 3 出现未知错误 - "Editor placeholder in source file",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44348597/

相关文章:

ios - 在可本地化文件中将文本编码更改为 No Explicit

iphone - 我应该使用什么 OpenGL ES 纹理格式才能在 iPad 上获得更好的动态范围?

Swift `UIMenuController` 自定义操作

iOS > 更改导航栏 zPosition 和 UIImageView

ios - UICollectionView 自定义布局标题 View

arrays - 使用 SwiftyJSON 将数组转换为 JSON

ios - Swift 检索 Firebase 数据

javascript - 无法使用console.log()

java - 将 Firebase 实时数据库中的值设置为 RadioButton

ios - 使用 iOS Evernote API 在 EDAMNote 中嵌入不可见元数据