> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create A Group

> Create public, private, or password-protected groups and optionally add members during creation using the CometChat iOS SDK.

<Accordion title="AI Integration Quick Reference">
  ```swift theme={null}
  // Create a group
  let group = Group(guid: "GUID", name: "Group Name", groupType: .public, password: nil)
  CometChat.createGroup(group: group,
      onSuccess: { group in }, onError: { error in })

  // Create group with members
  let members = [GroupMember(UID: "UID", groupMemberScope: .participant)]
  CometChat.createGroupWithMembers(group: group, members: members, banMembers: [],
      onSuccess: { response in }, onError: { error in })
  ```

  **Group types:** `.public` | `.password` | `.private`
  **Member scopes:** `.admin` | `.moderator` | `.participant`
</Accordion>

Create groups for multi-user conversations. You can create a group on its own with `createGroup()`, or create one and add members in a single call with `createGroupWithMembers()`. See the [Group Class](#group-class) reference at the bottom for all available fields.

## Create a Group

Use `createGroup()` to create a new group. Pass a [`Group`](/sdk/reference/entities#group) object with the group details.

| Group Type | Constant    | Description                               |
| ---------- | ----------- | ----------------------------------------- |
| Public     | `.public`   | Any user can join                         |
| Password   | `.password` | Users must provide the correct password   |
| Private    | `.private`  | Users must be added by an admin/moderator |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let guid = "cometchat-guid-11"
    let groupName = "TestGroup1"
    let password = "" // mandatory in case of password protected group type

    let group = Group(guid: guid, name: groupName, groupType: .private, password: password)

    CometChat.createGroup(group: group, onSuccess: { (group) in
        print("Group created successfully. " + group.stringValue())
    }, onError: { (error) in
        print("Group creation failed with error:" + error!.errorDescription)
    })
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSString *guid = @"cometchat-guid-101";
    NSString *name = @"TestGroup1";
    NSString *password = nil; // mandatory in case of password protected group type

    Group *group = [[Group alloc]initWithGuid:guid name:name groupType:groupTypePublic password:password];

    [CometChat createGroupWithGroup:group onSuccess:^(Group * group) {
        NSLog(@"Group created successfully. %@", [group stringValue]);
    } onError:^(CometChatException * error) {
        NSLog(@"Group creation failed with error: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

| Parameter | Description                                                   |
| --------- | ------------------------------------------------------------- |
| group     | An instance of [`Group`](/sdk/reference/entities#group) class |

On success, returns a [`Group`](/sdk/reference/entities#group) object with the created group's details.

<Warning>
  GUID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.
</Warning>

## Add Members While Creating a Group

Use `createGroupWithMembers()` to create a group and add members in one operation.

Parameters:

* `group` — The [`Group`](/sdk/reference/entities#group) object
* `members` — Array of [`GroupMember`](/sdk/reference/entities#groupmember) objects to add
* `banMembers` — Array of UIDs to ban (can be empty)

Create a [`GroupMember`](/sdk/reference/entities#groupmember) with: `GroupMember(UID:groupMemberScope:)`

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let group = Group(guid: "cometchat-uid-group1", name: "Hello Group", groupType: .public, password: nil)

    let members = [
        GroupMember(UID: "cometchat-uid-4", groupMemberScope: .participant)
    ]

    let banMembers = ["cometchat-uid-2"]

    CometChat.createGroupWithMembers(group: group, members: members, banMembers: banMembers, onSuccess: { response in
        print("Group created successfully", response)
    }, onError: { (error) in
        print("Error: \(String(describing: error?.errorDescription))")
    })
    ```
  </Tab>
</Tabs>

Returns an object with two keys:

* `group` — The created [`Group`](/sdk/reference/entities#group) object
* `members` — Object with UIDs as keys and `"success"` or error message as values

## Group Class

The [`Group`](/sdk/reference/entities#group) object has the following fields. Fields marked "Yes" in the Editable column can be modified after creation using `updateGroup()`.

| Field        | Editable                                                        | Information                                                               |
| ------------ | --------------------------------------------------------------- | ------------------------------------------------------------------------- |
| guid         | Needs to be specified at group creation. Cannot be edited later | A unique identifier for a group                                           |
| name         | Yes                                                             | Name of the group                                                         |
| type         | No                                                              | Type of the group: Can be 1. Public 2. Password 3. Private                |
| password     | No                                                              | Password for the group in case the group is of type password.             |
| icon         | Yes                                                             | An URL to group icon                                                      |
| description  | Yes                                                             | Description about the group                                               |
| owner        | Yes                                                             | UID of the owner of the group.                                            |
| metadata     | Yes                                                             | Additional data for the group as Dictionary                               |
| createdAt    | No                                                              | The unix timestamp of the time the group was created                      |
| updatedAt    | No                                                              | The unix timestamp of the time the group was last updated                 |
| hasJoined    | No                                                              | A boolean to determine if the logged in user is a member of the group.    |
| joinedAt     | No                                                              | The unix timestamp of the time the logged in user joined the group.       |
| scope        | Yes                                                             | Scope of the logged in user. Can be: 1. Admin 2. Moderator 3. Participant |
| membersCount | No                                                              | The number of members in the groups                                       |
| tags         | Yes                                                             | A list of tags to identify specific groups.                               |

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Join a Group" icon="right-to-bracket" href="/sdk/ios/join-group">
    Join public, private, or password-protected groups
  </Card>

  <Card title="Add Members" icon="user-plus" href="/sdk/ios/group-add-members">
    Add users to an existing group
  </Card>

  <Card title="Retrieve Groups" icon="list" href="/sdk/ios/retrieve-groups">
    Fetch and filter group lists
  </Card>

  <Card title="Groups Overview" icon="users" href="/sdk/ios/groups-overview">
    Overview of all group management features
  </Card>
</CardGroup>
