Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase runTransactionBlock

I'm reading firebase.google's example seen here https://firebase.google.com/docs/database/ios/save-data#save_data_as_transactions and I am trying to write my own version. I am having trouble as the firebase example leaves me more confused than i was before i started

All i am trying to do is when a person taps a button is that it ++ (or +=1) to the count and another button removes it

Can somebody help me figure out how to do this...another user on a previous question posted links to other language answers and i tried to write it in the swift language but I failed miserably

like image 231
RubberDucky4444 Avatar asked Jun 07 '16 03:06

RubberDucky4444


1 Answers

Thanks to the comments seen above I was able to get this to work

....runTransactionBlock { (currentData: FIRMutableData) -> FIRTransactionResult in

        var value = currentData.value as? Int

        if value == nil {
            value = 0
        }

        currentData.value = value! + 1
        return FIRTransactionResult.successWithValue(currentData)




    }
like image 53
RubberDucky4444 Avatar answered Oct 06 '22 00:10

RubberDucky4444