问题
My app currently uses Firebase as its backend. Currently, I'm using a transitionBlock to updated a value in my database. I'd like to run another transitionBlock after the first one finishes.
Any idea how to do this?
Code:
self.ref.child("blah").child(codeSelected).runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in
if var post = currentData.value as? [String : AnyObject], let uid = FIRAuth.auth()?.currentUser?.uid {
print(post)
var totalCount = post["total"] as? Int ?? 0
var usersList = post["users"] as? [String] ?? []
totalCount += 1
usersList.append(uid)
post["total"] = totalCount
post["users"] = usersList
currentData.value = post
print("Updated Blah")
self.updateUserValues() //This is where I'm calling the function for my second transitionBlock*
return FIRTransac tionResult.successWithValue(currentData)
}
return FIRTransactionResult.successWithValue(currentData)
}) { (error, committed, snapshot) in
if let error = error {
print(error.localizedDescription)
}
}
The second transition is very similar to the first one, it just has a different ref.
来源:https://stackoverflow.com/questions/37738144/run-2-transitionblocks-in-swift-firebase