> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-ios-ui-kit-sdk-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Groups

> Overview of CometChat iOS SDK group management including creating, joining, leaving groups, managing members, and transferring ownership.

<Info>
  **Quick Reference for AI Agents & Developers**

  * **Create group:** `CometChat.createGroup(group:onSuccess:onError:)`
  * **Join group:** `CometChat.joinGroup(GUID:groupType:password:onSuccess:onError:)`
  * **Leave group:** `CometChat.leaveGroup(GUID:onSuccess:onError:)`
  * **List groups:** `GroupsRequest.GroupsRequestBuilder().build()` → `groupsRequest.fetchNext(onSuccess:onError:)`
  * **Group types:** `.public`, `.private`, `.password`
  * **Related:** [Create Group](/sdk/ios/create-group) · [Retrieve Groups](/sdk/ios/retrieve-groups) · [Group Members](/sdk/ios/retrieve-group-members)
</Info>

Groups help your users to converse together in a single space. You can have three types of groups- private, public and password protected.

Each group includes three kinds of users- admin, moderator, member.

***

## Group Data Model

The `Group` class represents a CometChat group with all its properties and settings.

### Group Properties

| Property            | Type                   | Description                              |
| ------------------- | ---------------------- | ---------------------------------------- |
| `guid`              | `String`               | Unique group identifier (required)       |
| `name`              | `String?`              | Group display name (required)            |
| `icon`              | `String?`              | Group icon URL                           |
| `groupDescription`  | `String?`              | Group description                        |
| `owner`             | `String?`              | UID of the group owner                   |
| `groupType`         | `groupType`            | Type: `.public`, `.private`, `.password` |
| `password`          | `String?`              | Password for protected groups            |
| `metadata`          | `[String: Any]?`       | Custom metadata dictionary               |
| `createdAt`         | `Int`                  | Creation Unix timestamp                  |
| `updatedAt`         | `Int`                  | Last update Unix timestamp               |
| `joinedAt`          | `Int`                  | When current user joined                 |
| `scope`             | `GroupMemberScopeType` | Current user's scope in group            |
| `hasJoined`         | `Bool`                 | Whether current user has joined          |
| `membersCount`      | `Int`                  | Total number of members                  |
| `tags`              | `[String]`             | Array of group tags                      |
| `isBannedFromGroup` | `Bool`                 | Whether current user is banned           |

### Creating a Group Object

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // Public group
    let publicGroup = Group(guid: "group123", name: "Developers", groupType: .public, password: nil)

    // Private group
    let privateGroup = Group(guid: "group456", name: "Team Alpha", groupType: .private, password: nil)

    // Password protected group
    let protectedGroup = Group(guid: "group789", name: "VIP Room", groupType: .password, password: "secret123")

    // With all properties
    let group = Group(
        guid: "group123",
        name: "Developers",
        groupType: .public,
        password: nil,
        icon: "https://example.com/group-icon.png",
        description: "A group for developers"
    )
    group.metadata = ["category": "tech", "level": "advanced"]
    group.tags = ["featured", "active"]
    ```
  </Tab>
</Tabs>

### Success Response Example

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    // When fetching groups
    groupsRequest.fetchNext(onSuccess: { (groups) in
        for group in groups {
            print("GUID: \(group.guid)")
            print("Name: \(group.name ?? "")")
            print("Type: \(group.groupType)")
            print("Members: \(group.membersCount)")
            print("Has Joined: \(group.hasJoined)")
            print("My Scope: \(group.scope)")
            print("Owner: \(group.owner ?? "")")
            print("Created: \(Date(timeIntervalSince1970: TimeInterval(group.createdAt)))")
        }
    }, onError: { (error) in
        print("Error: \(error?.errorDescription ?? "")")
    })
    ```
  </Tab>
</Tabs>

### Group Type Enum

```swift theme={null}
enum groupType: Int {
    case `public` = 0   // Anyone can join
    case `private` = 1  // Invite only
    case password = 2   // Requires password to join
}
```

### GroupMemberScopeType Enum

```swift theme={null}
enum GroupMemberScopeType: Int {
    case admin = 0       // Full control
    case moderator = 1   // Can moderate members
    case participant = 2 // Regular member
}
```

### Common Error Codes

| Error Code              | Description                              |
| ----------------------- | ---------------------------------------- |
| `ERR_GUID_NOT_FOUND`    | Group with specified GUID does not exist |
| `ERR_ALREADY_JOINED`    | User has already joined the group        |
| `ERR_NOT_A_MEMBER`      | User is not a member of the group        |
| `ERR_WRONG_PASSWORD`    | Incorrect password for protected group   |
| `ERR_GROUP_NOT_JOINED`  | Must join group before performing action |
| `ERR_PERMISSION_DENIED` | Insufficient permissions for action      |
