Deleting a Group

You can delete a group by executing the delete(_:) method.

Swift 3:

  • // groupUri contains the reference URI of the target group.
    
    // Instantiate the group.
    let group = KiiGroup(uri: groupUri)
    
    do {
      // Delete the group.
      try group.deleteSynchronous()
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • // groupUri contains the reference URI of the target group.
    
    // Instantiate the group.
    let group = KiiGroup(uri: groupUri)
    
    // Delete the group.
    group.delete { (group : KiiGroup?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • // groupUri contains the reference URI of the target group.
    
    NSError *error = nil;
    
    // Instantiate the group.
    KiiGroup *group = [KiiGroup groupWithURI:groupUri];
    
    // Delete the group.
    [group deleteSynchronous:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // groupUri contains the reference URI of the target group.
    
    // Instantiate the group.
    KiiGroup *group = [KiiGroup groupWithURI:groupUri];
    
    // Delete the group.
    [group deleteWithBlock:^(KiiGroup *group, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

When a group is deleted, all data that belong to this group (i.e. buckets, KiiObjects, and topics) will be automatically deleted.

To learn how to get the URI of a group, see Creating a Group.

Considerations in deleting users

Deleting a group owner does not automatically delete groups associated with the owner even if such groups has no member. Therefore, orphan groups and data of such groups can continue to consume space on your application.

To avoid possible confusion, you should be aware of the following points.

  • When you delete a group owner

    A group will remain after you delete its owner. Since only a group owner can assign a new owner, and add and remove group members, no one will be able to manage the group.

    To avoid the deadlock, implement one of the following steps together with the step of deleting a group owner:

    • Change the group owner.
    • Reject the deletion of the group owner and prompt to assign a new group owner.
    • Delete the group with the owner.
  • When you delete the last group member

    When the last group member is deleted, there will be of course no user in the group. You can still access the group via its URI, but you will not be able to access the group if the URI is lost (For referencing a group, see Retrieving a Group and Relationship between a User and a Group).

    If your mobile app is not designed to save the group's URI, you need to carefully implement the user deletion. For example, you might want to implement the following logic:

    1. Get a list of groups that the user to be deleted is a member of.
    2. Get the members of each group on the list.
    3. When the user is deleted, delete groups whose sole member is the user.