【发布时间】:2019-04-21 17:36:38
【问题描述】:
由于某种原因,我从 firebase 检索数据后,数据确实检索成功。
func retrieveData(user: User) {
//let userID = Auth.auth().currentUser?.uid
let email = user.emailAddress!
// print(email)
databaseRef?.child("userTable").child(email).observe(.value, with: { (snapshot) in
// Get user value
print("whats up ")
if let value = snapshot.value as? [String:String] {
let res = value["posts"]
user.deserialize(data: res!)
if( user === self.u1) {
print("they are same obj") // this will print, so they are pointing to the same address
}
print(self.u1.posts) // this also printed the things I want
}
// ...
})
if( user === self.u1) {
print("they are same obj outside") // this also prints
}
print(self.u1.posts) // but once they exist closure, this one just become empty, as as user.posts
}
我真的不明白这里发生了什么。似乎数据只是在关闭后正确存储。另外,我不知道为什么闭包外的代码首先打印。非常感谢您的帮助!
这是运行结果
它们在外面是相同的 obj [:]
怎么了 他们是同一个obj ["a@hotmail 0": RadiUs.Post]
【问题讨论】:
标签: swift xcode firebase firebase-realtime-database