This is how the DB presented over Firebase
Parent
Match
User 1
Opponent : User 2
State : \"NotReady\"
Firebase uses a compare-and-set approach to transactions, which I'll describe below. It explains why you're getting nil
, but unfortunately means your current approach won't work.
When you invoke runTransactionBlock
, the Firebase client will immediately invoke your block with its best guess for the current value of the location. This best guess may be correct, but will be nil
if it doesn't know a current value for the location.
The Firebase client then sends the current value it gave your block and the value that you returned to the server. The Firebase server checks if the current value in the database is the same as the client's best guess. If so, it writes the new value you specified. If the value in the database is different, the server rejects the new value and send the rejection and the actual current value from the database to the client.
Your block is invoked again, but this time with the new "best guess" as to the current value.
This continues until either the server accepts the operation or until there have been too many tries (something 10 or 25 I think).