【问题标题】:Updating values in Firebase更新 Firebase 中的值
【发布时间】:2017-07-24 19:02:11
【问题描述】:
func updateFirebase(){
    myFun = thisIsMyFunTextView.text
    IAm = iAmTextView.text
    var profileKey = String()
    profileRef.queryOrdered(byChild: "uid").queryEqual(toValue: userID).observe(.value, with:{
        snapshot in
            for item in snapshot.children {
                guard let data = item as? FIRDataSnapshot else { continue }
                guard let dict = data.value as? [String: Any] else { continue }
                guard let profileKey = dict["profileKey"] else { continue }
                self.profileRef.child(profileKey as! String).child("bodyOfIAM").setValue(IAm)
                self.profileRef.child(profileKey as! String).child("bodyOfThisIsMyFun").setValue(myFun)
        }
    })
}
@IBAction func backButtonClicked(_ sender: Any) {
    updateFirebase()
    DispatchQueue.main.asyncAfter(deadline: .now() + 4, execute: {
        self.dismiss(animated: true)
    })
}

myFun 和 IAm 由用户对文本视图的更改成功定义。如果不触发这个 for in 循环,我无法提取 childByAutoID 值,该循环一旦调用就不会结束,即使出现新的视图控制器也会继续。 “bodyOfThisIsMyFun”在此循环期间在旧值和新值之间摇摆不定,而“bodyOfIAM”会立即正确重新定义并保持应有的状态。如何获取提取的新值来替换此处的旧值?

【问题讨论】:

    标签: ios firebase swift3 firebase-realtime-database


    【解决方案1】:

    我需要在 for...in 语句的末尾添加这行代码: self.profileRef.removeAllObservers()

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多