firebase dedicated a method to run Like count or any count, because sometimes user loss cell data, when they grab the snapshot LIKE value, once cell data is up they reconnct to firebase , even a few seconds, it will cause huge problem. say your post had 0 likes, you delay 3 seconds , 300 people already liked it, but your snapshot value still 0, so once you recover from data lose, you update the value to 1, haha. i tried the array.count, it works but i don't think it is effecient way to do it. say you got 3000 likes or more, you need to to run entire array to get the count every time ?
try this: mydataRef.runTransactionBlock({currentdata} -> TransactionResult in
this method will recheck your firebase data integrity, once you recover from your data lose, once it is reverified, you send your new data again. secure and fast , btw i am a newbie, just on this subject i dig sometime on it, if there is something wrong, please share. thanks