Skip to content

Delete By Key Name

Description

This operation deletes a single or multiple key-value pairs from the map.

Method

// Delete One Key-Value Pair
[[[Backendless.shared hive:(NSString *)hiveName] mapStore:(NSString *)keyName] deleteWithKey:(NSString *)key responseHandler:^(NSInteger)responseHandler errorHandler:^(Fault *)errorHandler];

// Delete Multiple Key-Value Pairs
[[[Backendless.shared hive:(NSString *)hiveName] mapStore:(NSString *)keyName] deleteWithKeys:(NSArray<NSString *> *)keys responseHandler:^(NSInteger)responseHandler errorHandler:^(Fault *)errorHandler];
// Delete One Key-Value Pair
Backendless.shared.hive(hiveName: String).mapStore(keyName: String).delete(key: String, responseHandler: ((Int) -> Void)!, errorHandler: ((Fault) -> Void)!)

// Delete Multiple Key-Value Pairs
Backendless.shared.hive(hiveName: String).mapStore(keyName: String).delete(keys: [String], responseHandler: ((Int) -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
keyName Key name identifying a map. String value.
key Key name identifying a key-value pair that must be deleted. String value.
keys An array of string values, where each value represents a key name identifying a key-value pair that must be deleted.

Return Value

The number of key-value pairs deleted from the map. Otherwise, returns 0 if no key-value pairs were deleted.

Example

Delete One Key-Value Pair

The example below deletes the "Apples" key and the associated value from the map.

[[[Backendless.shared hive:@"groceryStore"] mapStore:@"fruits"] deleteWithKey:@"Apples" responseHandler:^(NSInteger response) {
    // handle response
} errorHandler:^(Fault *fault) {
    // handle error
}];
Backendless.shared.hive("groceryStore").mapStore("fruits").delete(key: "Apples", responseHandler: { response in
    // handle response
}, errorHandler: { fault in
    // handle error
})

where:

Argument                Description
"groceryStore" Name of a hive where the operation is performed.
"fruits" Key name identifying a map.

Delete Multiple Key-Value Pairs

The example below deletes the "Apples" and "Oranges" keys and the associated values from the map.

[[[Backendless.shared hive:@"groceryStore"] mapStore:@"fruits"] deleteWithKeys:@[@"Apples", @"Oranges"] responseHandler:^(NSInteger response) {
    // handle response
} errorHandler:^(Fault *fault) {
    // handle error
}];
Backendless.shared.hive("groceryStore").mapStore("fruits").delete(keys: ["Apples", "Oranges"], responseHandler: { response in
    // handle response
}, errorHandler: { fault in
    // handle error
})

where:

Argument                Description
"groceryStore" Name of a hive where the operation is performed.
"fruits" Key name identifying a map.

Codeless Reference

map_api_delete_keys

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a map.
object key names A list of key names identifying key-value pairs.

Returns the number of deleted key-value pairs from the map.

Consider the following Map storage:
map_apI_example_map_store

The example below deletes two key-value pairs "Oranges" and "Apples" from the "fruits" map.

map_api_example_delete_keys

The map will look as shown below after the Codeless logic runs:
map_apI_example_map_store_9