Partial Update without the Overwrite Check

This method merges the data on the server with the key-value pairs sent from the client. You will send only key-value pairs you want to update from the client to the server. Note that you cannot delete the keys on the server with this method.

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")
    
    do{
      // Save and partially update the KiiObject.
      // This method appends the key-value pairs generated locally
      // to the KiiObject on the server.
      try object.saveSynchronous()
    } 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")
    
    // Save and partially update the KiiObject.
    // This method appends the key-value pairs generated locally
    // to the KiiObject on the server.
    object.save { (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"];
    
    NSError *error = nil;
    
    // Save and partially update the KiiObject.
    // This method appends the key-value pairs generated locally
    // to the KiiObject on the server.
    [object saveSynchronous:&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"];
    
    // Save and partially update the KiiObject.
    // This method appends the key-value pairs generated locally
    // to the KiiObject on the server.
    [object saveWithBlock:^(KiiObject *object, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

This is what is happening in the sample code:

  1. 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).
  2. Set the key-value pairs to update.
  3. Execute the save(_:) method to update the KiiObject. We are not using the overwrite check, so the update will be made unconditionally.

You do not need to execute the refresh(_:) method when updating a KiiObject partially. If you execute the refresh(_:) method, all key-value pairs on the server will be downloaded to the client. So, the update will be virtually the full update.

When you partially update a KiiObject, you cannot remove key-value pairs with the remove(_:forKey:) method. This is because the local key-value pairs are merged with those on the server. Fully update the KiiObject to remove key-value pairs.