So I have this code below:
func handleSendPost() {
let postRef = Global.FIRDB!.child("posts").childByAutoId()
for p in postComponents {
var values: [String : Any] = ["type": p.type!.rawValue, "text": p.text]
let childRef = reference.childByAutoId()
childRef.updateChildValues(values, withCompletionBlock: {
(err, ref) in
if err != nil {
print(err)
return
}
// object successfully saved
})
}
}
It's basically an iOS app for blogging. When someone creates a post, it's broken down into components that could be text or an image. After they're done editing, it will be stored on Firebase by calling the updateChildValues
async function. The problem is that I want to maintain the order of postComponents
. If I ran the code above, the order could mess up because it depends on how fast the updateChildValues
runs.
I've already tried using DispatchSemaphore
(iOS 10) to no avail.