Overwrite Current Value¶
Description¶
This operation overwrites the value of a key.
It is almost identical to Set Value By Key Name operation, but provides an additional parameter to control the overwrite process more flexibly.
Method¶
[[[Backendless.shared hive:(NSString *)hiveName] mapStore:(NSString *)keyName] setWithOverwriteWithKey:(NSString *)key value:(id)value overwrite:(BOOL)overwrite responseHandler:^(BOOL)responseHandler errorHandler:^(Fault *)errorHandler];
Backendless.shared.hive(hiveName: String).mapStore(keyName: String).setWithOverwrite(key: String, value: Any, overwrite: Bool, responseHandler: ((Bool) -> 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 |
Name of the key whose value is replaced. String value. |
value |
New value for the key. Can be of any data type. |
overwrite |
When set to true , forces the rename operation and name overwrite. Boolean value. |
Return Value¶
The return value depends on the operation behavior:
When the overwrite
parameter is set to true
:
Scenario 1: If the specified key is found, the operation overwrites the value and returns false
. The false
is returned to indicate that the new key-value pair was not created, but only the existing key-value pair was updated.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
When the overwrite
parameter is set to false
:
Scenario 1: If the specified key is found, the operation does not overwrite the value, but only returns false
indicating that the value was not overwritten and the new-key value pair was not created.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
Example¶
The example below overwrites the current value of the "Oranges"
key with a new value 1.29
. The invocation returns false
indicating that this value is updated. As you can see, the overwrite
parameter is set to true
, hence the operation overwrites the value.
[[[Backendless.shared hive:@"groceryStore"] mapStore:@"fruits"] setWithOverwriteWithKey:@"Oranges" value:@1.29 overwrite:true responseHandler:^(BOOL response) {
// handle response
} errorHandler:^(Fault *fault) {
// handle error
}];
Backendless.shared.hive("groceryStore").mapStore("fruits").setWithOverwrite(key: "Oranges", value: 1.29, overwrite: true, 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¶
where:
Argument | Description |
---|---|
hive name |
Name of a hive where the operation is performed. |
key name |
Key name identifying a map. |
object key name |
Key name identifying a key-value pair. |
value |
A value for a key. |
overwrite |
When set to true , forces the rename operation and name overwrite. |
The return value depends on the operation behavior:
When the overwrite
parameter is set to true
:
Scenario 1: If the specified key is found, the operation overwrites the value and returns false
. The false
is returned to indicate that the new key-value pair was not created, but only the existing key-value pair was updated.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
When the overwrite
parameter is set to false
:
Scenario 1: If the specified key is found, the operation does not overwrite the value, but only returns false
indicating that the value was not overwritten and the new-key value pair was not created.
Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true
.
Consider the following Map storage:
The example below overwrites the current value of the "Oranges"
key with a new value 1.29
.
The map will look as shown below after the Codeless logic runs: