Full Update without the Overwrite Check
This method overwrites the data on the server with the key-value pairs sent from the client (the data on the server will be lost).
The data will be overwritten unconditionally regardless of if the data on the server is updated by other clients.
Here is the sample code:
Swift:
-
// Instantiate a KiiObject. let object = KiiObject(uri: "Set the URI of an existing KiiObject here")! // Update key-value pairs. object.setObject(NSNumber(value: 1 as Int), forKey: "myid") object.setObject("John Doe Jr", forKey: "name") object.setObject("john_jr@example.com", forKey: "email") object.remove(forKey: "address") do{ // Save and fully update the KiiObject. // This method removes all key-value pairs from the KiiObject on the server and // adds the key-value pairs generated locally to the KiiObject. try object.saveAllFieldsSynchronous(true) } catch let error as NSError { // Handle the error. return }
-
// Instantiate a KiiObject. let object = KiiObject(uri: "Set the URI of an existing KiiObject here")! // Update key-value pairs. object.setObject(NSNumber(value: 1 as Int), forKey: "myid") object.setObject("John Doe Jr", forKey: "name") object.setObject("john_jr@example.com", forKey: "email") object.remove(forKey: "address") // Save and fully update the KiiObject. // This method removes all key-value pairs from the KiiObject on the server and // adds the key-value pairs generated locally to the KiiObject. object.saveAllFields(true, with: { (object : KiiObject?, error : Error?) -> Void in if error != nil { // Handle the error. return } })
Objective-C:
-
// Instantiate a KiiObject. KiiObject *object = [KiiObject objectWithURI:@"Set the URI of an existing KiiObject here"]; // Update key-value pairs. [object setObject:[NSNumber numberWithInt:1] forKey:@"myid"]; [object setObject:@"John Doe Jr" forKey:@"name"]; [object setObject:@"john_jr@example.com" forKey:@"email"]; [object removeObjectForKey:@"address"]; NSError *error = nil; // Save and fully update the KiiObject. // This method removes all key-value pairs from the KiiObject on the server and // adds the key-value pairs generated locally to the KiiObject. [object saveAllFieldsSynchronous:YES withError:&error]; if (error != nil) { // Handle the error. return; }
-
// Instantiate a KiiObject. KiiObject *object = [KiiObject objectWithURI:@"Set the URI of an existing KiiObject here"]; // Update key-value pairs. [object setObject:[NSNumber numberWithInt:1] forKey:@"myid"]; [object setObject:@"John Doe Jr" forKey:@"name"]; [object setObject:@"john_jr@example.com" forKey:@"email"]; [object removeObjectForKey:@"address"]; // Save and fully update the KiiObject. // This method removes all key-value pairs from the KiiObject on the server and // adds the key-value pairs generated locally to the KiiObject. [object saveAllFields:YES withBlock:^(KiiObject *object, NSError *error) { if (error != nil) { // Handle the error. return; } }];
This is what is happening in the sample code:
- Prepare a KiiObject to update. In this sample code, we are creating a KiiObject with its URI (Replace the URI in the code with the real one when you are running the code).
- Add key-value pairs with the
setObject(_:forKey:)
method and remove a key-value pair with theremove(forKey:)
method. Only the key-value pairs set here will be in the KiiOject after the updating. If you need to do so, you can execute therefresh(_:)
method beforehand to get all key-value pairs in the server (See Getting a KiiObject for the implementation example). - Execute the
saveAllFields(_:with:_:)
method to update the KiiObject. By setting the argument to true, we are disabling the overwrite check; the update will be made unconditionally.