> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Join A Group

> Learn how to join public, password-protected, and private groups, and receive real-time join events using the CometChat iOS SDK.

<Accordion title="AI Integration Quick Reference">
  ```swift theme={null}
  // Join a public group
  CometChat.joinGroup(GUID: "GUID", groupType: .public, password: nil,
      onSuccess: { group in }, onError: { error in })

  // Join a password-protected group
  CometChat.joinGroup(GUID: "GUID", groupType: .password, password: "password123",
      onSuccess: { group in }, onError: { error in })

  // Listen for member joined events via CometChatGroupDelegate
  func onGroupMemberJoined(action: ActionMessage, joinedUser: User, joinedGroup: Group) { }
  ```
</Accordion>

Join a group to start sending and receiving messages in it. Public groups can be joined freely, password groups require the correct password, and private groups require an admin to add you (no direct join).

## Join a Group

Use `joinGroup()` to join a group.

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

    CometChat.joinGroup(GUID: guid, groupType: .public, password: nil, onSuccess: { (group) in
        print("Group joined successfully. " + group.stringValue())
    }, onError: { (error) in
        print("Group joining failed with error:" + error!.errorDescription)
    })
    ```
  </Tab>

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

    [CometChat joinGroupWithGUID:guid groupType:groupTypePublic password:password onSuccess:^(Group * group) {
        NSLog(@"Group joined successfully: %@", [group stringValue]);
    } onError:^(CometChatException * error) {
        NSLog(@"Group joining failed with exception: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

| Parameter   | Description                            |
| ----------- | -------------------------------------- |
| `GUID`      | The GUID of the group to join          |
| `groupType` | `.public`, `.password`, or `.private`  |
| `password`  | Required for password-protected groups |

Once joined, you can send and receive messages in the group. CometChat tracks joined groups — you don't need to rejoin each session. Check `hasJoined` on the `Group` object to verify membership.

The method returns a [`Group`](/sdk/reference/entities#group) object with `hasJoined` set to `true`.

## Real-time Group Member Joined Events

Register a `CometChatGroupDelegate` to receive events when members join.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    class ViewController: UIViewController, CometChatGroupDelegate {
        
        override func viewDidLoad() {
            super.viewDidLoad()
            CometChat.groupdelegate = self
        }
        
        func onGroupMemberJoined(action: ActionMessage, joinedUser: User, joinedGroup: Group) {
            print("\(joinedUser.name ?? "") joined \(joinedGroup.name ?? "")")
        }
        
        func onMemberAddedToGroup(action: ActionMessage, addedBy: User, addedUser: User, addedTo: Group) {
            print("\(addedUser.name ?? "") was added to \(addedTo.name ?? "")")
        }
    }
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    @interface ViewController ()<CometChatGroupDelegate>
    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        [CometChat setGroupdelegate:self];
    }

    - (void)onMemberAddedToGroup:(Action *)action addedBy:(User * _Nonnull)addedBy addedUser:(User * _Nonnull)addedUser addedTo:(Group * _Nonnull)addedTo {
        // When any member is added in the group this function will be called
    }

    @end
    ```
  </Tab>
</Tabs>

<Warning>
  Always remove group listeners when they're no longer needed (e.g., on view dismissal). Failing to remove listeners can cause memory leaks and duplicate event handling.
</Warning>

## Missed Group Member Joined Events

When fetching message history, join events appear as [`Action`](/sdk/reference/messages#action) messages with:

* `action` — `"joined"`
* `actionBy` — [`User`](/sdk/reference/entities#user) who joined
* `actionFor` — [`Group`](/sdk/reference/entities#group) that was joined

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Leave a Group" icon="right-from-bracket" href="/sdk/ios/leave-group">
    Allow members to leave a group
  </Card>

  <Card title="Retrieve Group Members" icon="users" href="/sdk/ios/retrieve-group-members">
    Fetch the list of members in a group
  </Card>

  <Card title="Send Messages" icon="paper-plane" href="/sdk/ios/send-message">
    Send messages to group conversations
  </Card>

  <Card title="Add Members" icon="user-plus" href="/sdk/ios/group-add-members">
    Programmatically add members to a group
  </Card>
</CardGroup>
