概要
Firebase/RealtimeDatabaseでインクリメンタルな値を扱う簡単な仕組みがない。
そのためのコードを記載する。
何らかのイベント回数などを初期化して累積増加させたい時に使用できる。
increment
FIRDatabase.database().reference().child("test1").observeSingleEvent(of: .value, with: { (snapshot) in
var count:Int = 1
if !(snapshot.value is NSNull){
count = (snapshot.value as! Int) + 1
}
FIRDatabase.database().reference()
.child("test1")
.setValue(count)
}) { (error) in
print(error.localizedDescription)
}