This is how DB presented over Firebase
Parent Match User 1 Opponent : User 2 State : "NotReady" User 2 Opponent : User 1 State : "NotReady"
I am trying to update values State(each user separately) using RunTransaction.
State
What I tried to do:
if he suddenly left - abort the transaction (Possible condition - if two closing events are executed simultaneously, one update "Status" and the other deletes all keys (removeValue)
removeValue)
let path = "Parent/Match/User 1/state" let futureRef = Firebase(url: path) futureRef.runTransactionBlock({ (currentData:FMutableData!) in let value = currentData.value as? String if value != nil { currentData.value = "Ready" return FTransactionResult.successWithValue(currentData) } return FTransactionResult.abort() }, andCompletionBlock: { // Completion Check (error:NSError!, success:Bool, data:FDataSnapshot!) in if error == nil && success && data.value as! String == "Ready" { //Value is not null(not removed) and he is ready ManipulateUI() } else { //Value deleted } } )
But for some reason - I get currentData, which nilgoes directly to Abort. Any suggestions? Thanks!!!
nil
Abort
Firebase , . , nil, , , .
runTransactionBlock Firebase . , nil, .
runTransactionBlock
Firebase , , , . Firebase , , . , , . , .
, " " .
, (- 10 25, ).
Source: https://habr.com/ru/post/1624378/More articles:Sqlalchemy: subquery in FROM must have an alias - pythonHow safe is ref when used with unsafe code? - c #Android button back will move to a specific fragment - androidFind the rows where the child collection contains all the elements of the list - c #How to restart Windows 8/10 and go to Advanced Boot settings using WinAPI? - c ++Install LAMP Web Server on Amazon Linux - lampHow can I force individual lodash modules into a vendor chunk using webpack? - javascriptJava encryption and decryption in my Spring boot application - springWhat are the benefits of having a feature behind an object? - scalaChange overflow menu border in Android - androidAll Articles