Skip to content

Increment by 1, return current

Atomically increments by one the current value and returns the updated (current) value of the counter. Multiple concurrent client requests are guaranteed to return unique updated value.

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

where:

Argument                Description
counterName name of the counter to increment.

Example

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

//

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

//

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