Getting a Group List for a Member

Users can get a list of groups that they are a member of.

The following sample code shows how to get a list of groups that the current user is a member of.

Swift:

  • // Get the currently logged-in user.
    let user = KiiUser.current()
    
    do{
      // Get a list of groups that the current user is a member of.
      let memberGroups = try user!.memberOfGroupsSynchronous() as! [KiiGroup]
    
      for group in memberGroups{
        // Do something.
      }
    }catch(let error as NSError){
      // Handle the error.
      return
    }
  • // Get the currently logged-in user.
    let user = KiiUser.current()
    
    // Get a list of groups that the current user is a member of.
    user!.memberOfGroups({ (user :KiiUser?, results : [Any]?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      let memberGroups = results as! [KiiGroup]
    
      for group in memberGroups{
        // Do something.
      }
    })

Objective-C:

  • // Get the currently logged-in user.
    KiiUser* user = [KiiUser currentUser];
    
    NSError* error = nil;
    
    // Get a list of groups that the current user is a member of.
    NSArray* memberGroups = [user memberOfGroupsSynchronous:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
    
    for (KiiGroup* group in memberGroups) {
      // Do something.
    }
  • // Get the currently logged-in user.
    KiiUser* user = [KiiUser currentUser];
    
    // Get a list of groups that the current user is a member of.
    [user memberOfGroupsWithBlock:^(KiiUser *user, NSArray *results, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    
      for (KiiGroup* group in results) {
        // Do something.
      }
    }];