2017-07-24 57 views
0
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通过用户对文本视图的更改成功定义。我无法提取childByAutoID值,如果没有在循环中触发此操作,并且不会一次调用就结束,即使在呈现新的视图控制器时也会继续。在此循环中,“bodyOfThisIsMyFun”在旧值和新值之间摇摆,而“bodyOfIAM”被正确地重新定义并保持原样。我如何获取提取的新值以替换旧值?更新Firebase中的值

回答

0

我需要在为...在声明的末尾添加这行代码: self.profileRef.removeAllObservers()