Skip to content

Increment by N, return current

Atomically adds the given value to the current value and returns the updated (current) value of the counter. Multiple concurrent client requests are guaranteed to return updated value.

- (void)addAndGetWithCounterName:(NSString * _Nonnull)counterName value:(NSInteger)value responseHandler:^(NSInteger)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func addAndGet(counterName: String, value: Int, responseHandler: ((Int) -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
counterName name of the counter to update.
value number to add to the current counter value

Example

[Backendless.shared.counters addAndGetWithCounterName:@"MyCounter" value:7 responseHandler:^(NSInteger value) {
    NSLog(@"Current value = %li", value);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];

//

id<IAtomic> myCounter = [Backendless.shared.counters ofCounterName:@"MyCounter"];
[myCounter addAndGetWithValue:7 responseHandler:^(NSInteger value) {
    NSLog(@"Current value = %li", value);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];}
Backendless.shared.counters.addAndGet(counterName: "MyCounter", value: 7, responseHandler: { value in
    print("Current value = \(value)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

//

let myCounter = Backendless.shared.counters.of(counterName: "MyCounter")
myCounter.addAndGet(value: 7, responseHandler: { value in
    print("Current value = \(value)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})