I am trying to store the Firebase server time using FIRServerValue.timestamp() with posts but noticed that my listener keeps on getting called twice. Printing in my console, I see the duplicate of the post but with two different timestamps milliseconds apart. Any help is greatly appreciated.
Listener:
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()
})
My posting:
let post: Dictionary<String, AnyObject> = [
"storeId": storeId!,
"specificId": specificId.text!,
"postedDate": FIRServerValue.timestamp()
]
let firebasePost = DataService.ds.REF_POSTS.childByAutoId()
firebasePost.setValue(post)