我正在尝试使用带有帖子的 FIRServerValue.timestamp()存储Firebase服务器时间,但注意到我的侦听器一直被调用两次。在我的控制台中打印,我看到帖子的副本,但有两个不同的时间戳相隔毫秒。非常感谢任何帮助。
监听器:
DataService.ds.REF_POSTS.queryOrderedByChild("storeId").queryEqualToValue("\(self.specificId)").observeEventType(.Value, withBlock: {snapshot in
if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshot{
print("SNAP: \(snap)")
if let postDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let post = Post(postKey: key, postData: postDict)
self.posts.insert(post, atIndex: 0)
}
}
}
self.collection.reloadData()
})
我的帖子:
let post: Dictionary<String, AnyObject> = [
"storeId": storeId!,
"specificId": specificId.text!,
"postedDate": FIRServerValue.timestamp()
]
let firebasePost = DataService.ds.REF_POSTS.childByAutoId()
firebasePost.setValue(post)