> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-agent-in-group-react-v6.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Retrieve Groups

> Fetch, filter, and search groups using the CometChat iOS SDK. Includes pagination, tag-based filtering, joined-only groups, and online member counts.

<Accordion title="AI Integration Quick Reference">
  ```swift theme={null}
  // Fetch groups list
  let request = GroupsRequest.GroupsRequestBuilder()
      .set(limit: 30).build()
  request.fetchNext(onSuccess: { groups in }, onError: { error in })

  // Get specific group details
  CometChat.getGroup(GUID: "GUID", onSuccess: { group in }, onError: { error in })

  // Fetch only joined groups
  let joinedRequest = GroupsRequest.GroupsRequestBuilder()
      .set(limit: 30).set(joinedOnly: true).build()

  // Get online member count
  CometChat.getOnlineGroupMemberCount(["GUID"],
      onSuccess: { countData in }, onError: { error in })
  ```
</Accordion>

Fetch the list of [`Group`](/sdk/reference/entities#group) objects the logged-in user can see, get details for a specific group, or check online member counts.

## Retrieve List of Groups

Use `GroupsRequestBuilder` to fetch groups with filtering, searching, and pagination.

### Set Limit

Sets the number of groups to fetch per request.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupsRequest = GroupsRequest.GroupsRequestBuilder()
        .set(limit: 30)
        .build()
    ```
  </Tab>
</Tabs>

### Set Search Keyword

Filters groups by a search string.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupsRequest = GroupsRequest.GroupsRequestBuilder()
        .set(searchKeyword: "abc")
        .set(limit: 30)
        .build()
    ```
  </Tab>
</Tabs>

### Joined Only

When `true`, returns only groups the logged-in user has joined.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupsRequest = GroupsRequest.GroupsRequestBuilder()
        .set(joinedOnly: true)
        .set(limit: 30)
        .build()
    ```
  </Tab>
</Tabs>

### Set Tags

Filters groups by specified tags.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupsRequest = GroupsRequest.GroupsRequestBuilder()
        .set(limit: 30)
        .set(tags: ["tag1", "tag2"])
        .build()
    ```
  </Tab>
</Tabs>

### With Tags

When `true`, includes tag data in the returned group objects.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let groupsRequest = GroupsRequest.GroupsRequestBuilder()
        .set(limit: 30)
        .withTags(true)
        .build()
    ```
  </Tab>
</Tabs>

After configuring the builder, call `build()` to get the `GroupsRequest` object, then call `fetchNext()` to retrieve groups.

<Note>
  The list only includes public and password-protected groups. Private groups appear only if the user is a member.
</Note>

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let limit = 30

    let groupsRequest = GroupsRequest.GroupsRequestBuilder(limit: limit).build()

    groupsRequest.fetchNext(onSuccess: { (groups) in
        for group in groups {
            print("Group: \(group.stringValue())")
        }
    }, onError: { (error) in
        print("Error: \(error?.errorDescription)")
    })
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSInteger limit = 30;

    GroupsRequest *groupRequest = [[[GroupsRequestBuilder alloc]initWithLimit:limit] build];

    [groupRequest fetchNextOnSuccess:^(NSArray<Group *> * groups) {
        for (Group *group in groups) {
            NSLog(@"Group: %@", [group stringValue]);
        }
    } onError:^(CometChatException * error) {
        NSLog(@"Error: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

## Retrieve Particular Group Details

Use `getGroup()` to fetch a specific group's details by GUID.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let guid = "cometchat-guid-1"

    CometChat.getGroup(GUID: guid, onSuccess: { (group) in
        print("Group: \(group.stringValue())")
    }, onError: { (error) in
        print("Error: \(error?.errorDescription)")
    })
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSString *guid = @"cometchat-guid-1";

    [CometChat getGroupWithGUID:guid onSuccess:^(Group * group) {
        NSLog(@"Group: %@", [group stringValue]);
    } onError:^(CometChatException * error) {
        NSLog(@"Error: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

| Parameter | Description                    |
| --------- | ------------------------------ |
| `GUID`    | The GUID of the group to fetch |

The method returns a [`Group`](/sdk/reference/entities#group) object.

## Get Online Group Member Count

Use `getOnlineGroupMemberCount()` to get the number of online members in specified groups.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let guids = ["cometchat-guid-1", "cometchat-guid-2"]

    CometChat.getOnlineGroupMemberCount(guids, onSuccess: { countData in
        // countData: [String: Int] - GUID as key, count as value
        for (guid, count) in countData {
            print("Group \(guid): \(count) online members")
        }
    }, onError: { error in
        print("Error: \(error?.errorDescription)")
    })
    ```
  </Tab>
</Tabs>

Returns a `[String: Int]` dictionary with GUIDs as keys and online member counts as values.

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Create Group" icon="plus" href="/sdk/ios/create-group">
    Create public, private, or password-protected groups
  </Card>

  <Card title="Retrieve Group Members" icon="users" href="/sdk/ios/retrieve-group-members">
    Fetch and filter members of a specific group
  </Card>
</CardGroup>
