Skip to content

Delete Random Key Items


This operation returns the specified number of random elements and deletes them afterwards from a set.


[[[Backendless.shared hive:(NSString *)hiveName] setStore:(NSString *)keyName] getRandomAndDeleteWithCount:(NSInteger)count responseHandler:^(NSArray *)responseHandler errorHandler:^(Fault *)errorHandler];
Backendless.shared.hive(hiveName: String).setStore(keyName: String).getRandomAndDelete(count: Int, responseHandler: (([Any]) -> Void)!, errorHandler: ((Fault) -> Void)!)


Argument                Description
hiveName Name of a hive where the operation is performed. String value.
keyName Key name identifying a set. String value.
count Optional parameter. Identifies the number of values to delete and return in the response. Defaults to 1.

Return Value

An array containing deleted values. Each individual value is of any data type.


The example below returns two random values and deletes them from the "cars" set. By specifying the count parameter you can return/delete the specified number of elements.

[[[Backendless.shared hive:@"transport"] setStore:@"cars"] getRandomAndDeleteWithCount:2 responseHandler:^(NSArray *response) {
    // handle response
} errorHandler:^(Fault *fault) {
    // handle error
Backendless.shared.hive(transport).setStore("cars").getRandomAndDelete(count: 2, responseHandler: { response in
    // handle response
}, errorHandler: { fault in
    // handle error


Argument                Description
"transport" Name of a hive where the operation is performed.
"cars" Key name identifying a set.

Response Example


Codeless Reference



Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a set.
count Specify the number of items to delete.

Returns a list containing deleted values.

Consider the following Set storage:

The example below deletes a random value from the "cars" set:


The logic produces the following output: