【发布时间】:2016-09-15 15:16:24
【问题描述】:
我正在按照 firebase 中显示的说明进行操作,但即使在确保文本条目是 String 类型之后,我仍然会崩溃。
这是错误:
由于未捕获的异常“InvalidPathValidation”而终止应用程序,原因:“(子:)必须是非空字符串且不包含“。” '#' '$' '[' 或 ']''
这是代码:
import UIKit
import Firebase
import FirebaseDatabase
import FirebaseAuth
class BioEditViewController: UIViewController {
@IBOutlet weak var bioTextView: UITextView!
let databaseRef = FIRDatabase.database().reference()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(animated: Bool) {
let userID = FIRAuth.auth()?.currentUser?.uid
databaseRef.child("users").child(userID!).observeSingleEventOfType(.Value, withBlock: { (snapshot) in
// Get user level
let userBio = snapshot.value!["userBio"] as! String
self.bioTextView.text = userBio
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func doneSave(sender: UIButton) {
let textView = bioTextView.text
self.dismissViewControllerAnimated(false, completion: nil)
databaseRef.child("users/(user.uid)/userBio").setValue(textView)
}
}
我只是想更新一个特定的孩子:userBio 而不会影响整个对象。
【问题讨论】:
-
你在哪一行得到这个错误?
-
对于 databaseRef.child("users/(user.uid)/userBio").setValue(textView)