Firebase runTransactionBlock does not work when persistenceEnabled = false

时间:2016-07-11 19:26:58

标签: ios swift firebase firebase-realtime-database

I'm trying to update my object count using a runTransaction block, but the FIRMutable data returned is always (null).

If I enable persistence on FirebaseDatabase, it works, however I don't want to have it enabled.

let artworkRef = FIRDatabase.database().reference().child(doodlesKey).child(artwork.uid)
artworkRef.runTransactionBlock { (mutableData) -> FIRTransactionResult in
    if var artworkData = mutableData.value as? [String: AnyObject] {
        var bookmarkCount = artworkData["bookmarkCount"] as? Int ?? 0
        bookmarkCount += 1
        artworkData["bookmarkCount"] = bookmarkCount
        mutableData.value = artworkData
        return FIRTransactionResult.successWithValue(mutableData)
    }
    return FIRTransactionResult.successWithValue(mutableData)
}

0 个答案:

没有答案