A logical counter representation for performing numeric updates that need
to be synchronized as sequentially consistent events rather than individual
reassignments of the number.
For instance, offline Client 1 and Client 2 which both see Counter.value
as 0, can both call Counter.increment(1). Once online, the value will
converge to 2.
The above property schema can be extended to allow a nullable counter.
A Counter never stores null values itself, but the counter property
on the Realm.Object (e.g. myRealmObject.myCounter) can be null.
To create a counter from a previously null value, or to reset a nullable
counter to null, use UpdateMode.Modified or UpdateMode.All.
A logical counter representation for performing numeric updates that need to be synchronized as sequentially consistent events rather than individual reassignments of the number.
For instance, offline Client 1 and Client 2 which both see
Counter.value
as0
, can both callCounter.increment(1)
. Once online, the value will converge to2
.Counter types are not supported as:
Mixed
values$0
) in filtered()Counter
when filtering, useCounter.value
.Declaring a counter
A property schema is declared as either:
"counter"
{ type: "int", presentation: "counter" }
Creating a counter
Use a
number
when creating your counter on a Realm.Object.Updating the count
Use the instance methods to update the underlying count.
Nullability
The above property schema can be extended to allow a nullable counter. A
Counter
never storesnull
values itself, but the counter property on the Realm.Object (e.g.myRealmObject.myCounter
) can benull
.To create a counter from a previously
null
value, or to reset a nullable counter tonull
, use UpdateMode.Modified or UpdateMode.All.