Adding and Removing a Member

Users can be added to groups and removed from groups.

Adding a member

A group owner can add additional members to their group with the addUser() method:

Swift:

  • // Instantiate a user.
    let user2 = KiiUser(uri: "Set the URI of an existing user here")
    
    // Add the user to the group.
    group.add(user2)
    
    do {
      // Save the group on the server.
      try group.saveSynchronous()
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • // Instantiate a user.
    let user2 = KiiUser(uri: "Set the URI of an existing user here")
    
    // Add the user to the group.
    group.add(user2)
    
    // Save the group on the server.
    group.save { (group : KiiGroup?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • // Instantiate a user.
    KiiUser *user2 = [KiiUser userWithURI:@"Set the URI of an existing user here"];
    
    // Add the user to the group.
    [group addUser:user2];
    
    // Save the group on the server.
    NSError *error;
    [group saveSynchronous:&error];
    
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Instantiate a user.
    KiiUser *user2 = [KiiUser userWithURI:@"Set the URI of an existing user here"];
    
    // Add the user to the group.
    [group addUser:user2];
    
    // Save the group on the server.
    [group saveWithBlock:^(KiiGroup *group, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

Make sure to execute the save(_:) method to reflect the changes.

Removing a member

A group owner can remove existing members from their group with the removeUser() method:

Swift:

  • // Instantiate a user.
    let user2 = KiiUser(uri: "Set the URI of an existing user here")
    
    // Remove the user from the group.
    group.remove(user2)
    
    do {
      // Save the group on the server.
      try group.saveSynchronous()
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • // Instantiate a user.
    let user2 = KiiUser(uri: "Set the URI of an existing user here")
    
    // Remove the user from the group.
    group.remove(user2)
    
    // Save the group on the server.
    group.save { (group : KiiGroup?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • // Instantiate a user.
    KiiUser *user2 = [KiiUser userWithURI:@"Set the URI of an existing user here"];
    
    // Remove the user from the group.
    [group removeUser:user2];
    
    // Save the group on the server.
    NSError *error;
    [group saveSynchronous:&error];
    
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Instantiate a user.
    KiiUser *user2 = [KiiUser userWithURI:@"Set the URI of an existing user here"];
    
    // Remove the user from the group.
    [group removeUser:user2];
    
    // Save the group on the server.
    [group saveWithBlock:^(KiiGroup *group, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

Make sure to execute the save(_:) method to reflect the changes.