> ## 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.

# Update A Group

> Guide to updating group details using the CometChat iOS SDK updateGroup method (owner/admin only).

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

  * **Update group:** `CometChat.updateGroup(group:onSuccess:onError:)`
  * **Updatable fields:** name, description, icon, metadata, tags
  * **Permission:** Only group owner or admin can update
  * **Related:** [Create Group](/sdk/ios/create-group) · [Delete Group](/sdk/ios/delete-group) · [Groups Overview](/sdk/ios/groups-overview)
</Info>

## Update Group

*In other words, as a group owner, how can I update the group details?*

You can update the existing details of the group using the `updateGroup()` method.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let GUID = "GUID";
    let groupName = "Hello Group!";
    let groupType: CometChat.groupType = .public;

    let groupTobeUpdated = Group(guid: GUID, name: groupName, groupType: groupType, password: nil)

    CometChat.updateGroup(group: groupTobeUpdated, onSuccess: { (group) in

      print("Groups details updated successfully. " + group.stringValue())

    }) { (error) in

       print("Group details update 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
    NSInteger limit = 30;

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

    [CometChat updateGroupWithGroup:groupToBeUpdated onSuccess:^(Group * group) {

        NSLog(@"Groups details updated successfully. %@",[group stringValue]);

    } onError:^(CometChatException * error) {

        NSLog(@"Group details update failed with error: %@",[error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

This method takes an instance of the `Group` class as a parameter that should contain the data that you wish to update.

| Parameter | Description                  |
| --------- | ---------------------------- |
| group     | an instance of class `Group` |

After a successful update of the group, you will receive an instance of the `Group` class containing update information of the group.

<Accordion title="Sample Payload - updateGroup() Request">
  **Method Signature:**

  | Parameter | Type                                               | Description                                |
  | --------- | -------------------------------------------------- | ------------------------------------------ |
  | group     | [Group](/sdk/ios/groups-overview#group-properties) | Group object with updated properties       |
  | onSuccess | (Group) -> Void                                    | Success callback with updated Group object |
  | onError   | (CometChatException?) -> Void                      | Error callback with exception details      |

  **Group Object (Input):**

  | Parameter   | Type                                             | Description                                                           |
  | ----------- | ------------------------------------------------ | --------------------------------------------------------------------- |
  | guid        | String                                           | Unique group identifier (required). Example: `"cometchat-guid-1"`     |
  | name        | String                                           | Updated group name. Example: `"Updated Test Group"`                   |
  | groupType   | [GroupType](/sdk/ios/groups-overview#group-type) | Group type (required). Example: `.public`                             |
  | icon        | String?                                          | Updated group icon URL. Example: `"https://example.com/new-icon.png"` |
  | description | String?                                          | Updated group description. Example: `"Updated description"`           |
  | metadata    | \[String: Any]?                                  | Updated custom metadata. Example: `["key": "value"]`                  |
  | tags        | \[String]?                                       | Updated group tags. Example: `["updated", "team"]`                    |
  | password    | String?                                          | Password (required for password-protected groups). Example: `nil`     |

  **Updatable Properties:**

  | Property    | Type            | Description               |
  | ----------- | --------------- | ------------------------- |
  | name        | String          | Group display name        |
  | icon        | String?         | Group icon URL            |
  | description | String?         | Group description text    |
  | metadata    | \[String: Any]? | Custom key-value metadata |
  | tags        | \[String]       | Array of searchable tags  |

  **Non-Updatable Properties:**

  | Property     | Description                                                         |
  | ------------ | ------------------------------------------------------------------- |
  | guid         | Cannot be changed after creation                                    |
  | groupType    | Cannot be changed after creation                                    |
  | owner        | Use [Transfer Ownership](/sdk/ios/transfer-group-ownership) instead |
  | membersCount | Automatically managed by system                                     |
  | createdAt    | Set at creation time                                                |

  **Prerequisites:**

  | Requirement            | Description                                        |
  | ---------------------- | -------------------------------------------------- |
  | User logged in         | User must be authenticated via `CometChat.login()` |
  | Owner/Admin permission | User must be the owner or admin of the group       |
  | Valid GUID             | Group with specified GUID must exist               |
  | Valid name             | Group name cannot be empty                         |
</Accordion>

<Accordion title="Sample Payload - updateGroup() Success Response">
  **Success Callback Parameter:**

  | Parameter | Type                                               | Description                                                                |
  | --------- | -------------------------------------------------- | -------------------------------------------------------------------------- |
  | group     | [Group](/sdk/ios/groups-overview#group-properties) | Updated Group object. See [Group Object](#updategroup-success-group) below |

  <span id="updategroup-success-group" />

  **Updated [Group](/sdk/ios/groups-overview#group-properties) Object:**

  | Parameter    | Type                                                 | Description                                                     |
  | ------------ | ---------------------------------------------------- | --------------------------------------------------------------- |
  | guid         | String                                               | Group's unique ID. Example: `"cometchat-guid-1"`                |
  | name         | String                                               | Updated group name. Example: `"Updated Test Group"`             |
  | groupType    | [GroupType](/sdk/ios/groups-overview#group-type)     | Group type. Example: `.public`                                  |
  | icon         | String?                                              | Updated icon URL. Example: `"https://example.com/new-icon.png"` |
  | description  | String?                                              | Updated description. Example: `"Updated description"`           |
  | owner        | String                                               | Group owner UID. Example: `"cometchat-uid-1"`                   |
  | membersCount | Int                                                  | Number of members. Example: `15`                                |
  | createdAt    | Int                                                  | Creation timestamp. Example: `1699700000`                       |
  | updatedAt    | Int                                                  | Update timestamp. Example: `1699800000`                         |
  | hasJoined    | Bool                                                 | Whether current user has joined. Example: `true`                |
  | joinedAt     | Int                                                  | Join timestamp. Example: `1699710000`                           |
  | scope        | [MemberScope](/sdk/ios/groups-overview#member-scope) | Current user's scope. Example: `.admin`                         |
  | metadata     | \[String: Any]?                                      | Updated custom metadata                                         |
  | tags         | \[String]                                            | Updated group tags                                              |

  **[GroupType](/sdk/ios/groups-overview#group-type) Enum Values:**

  | Value     | Description                      |
  | --------- | -------------------------------- |
  | .public   | Anyone can join without approval |
  | .private  | Requires invitation to join      |
  | .password | Requires password to join        |

  **[MemberScope](/sdk/ios/groups-overview#member-scope) Enum Values:**

  | Value        | Description                                 |
  | ------------ | ------------------------------------------- |
  | .admin       | Administrator privileges (can update group) |
  | .moderator   | Moderator privileges                        |
  | .participant | Regular member (cannot update group)        |

  **Real-time Event Triggered:**

  | Event          | Delegate Method          | Description                              |
  | -------------- | ------------------------ | ---------------------------------------- |
  | onGroupUpdated | `CometChatGroupDelegate` | Notifies all group members of the update |
</Accordion>

<Accordion title="Sample Payload - updateGroup() Error Response">
  **Error Callback Parameter:**

  | Parameter | Type                | Description                             |
  | --------- | ------------------- | --------------------------------------- |
  | error     | CometChatException? | Error object containing failure details |

  **CometChatException Object:**

  | Parameter        | Type            | Description                                                |
  | ---------------- | --------------- | ---------------------------------------------------------- |
  | errorCode        | String          | Machine-readable error code. Example: `"ERR_NOT_A_MEMBER"` |
  | errorDescription | String          | Human-readable error message                               |
  | errorDetails     | \[String: Any]? | Additional error context                                   |

  **Common Error Codes:**

  | Error Code              | Description                       | Resolution                            |
  | ----------------------- | --------------------------------- | ------------------------------------- |
  | ERR\_NOT\_LOGGED\_IN    | User is not logged in             | Login first using `CometChat.login()` |
  | ERR\_GUID\_NOT\_FOUND   | Group does not exist              | Verify the GUID is correct            |
  | ERR\_GROUP\_NOT\_FOUND  | Group does not exist              | Verify the GUID is correct            |
  | ERR\_NOT\_A\_MEMBER     | User is not a member of the group | Join the group first                  |
  | ERR\_PERMISSION\_DENIED | No permission to update           | Only owner or admin can update        |
  | ERR\_EMPTY\_GROUP\_NAME | Group name is empty               | Provide a valid group name            |
  | ERR\_INVALID\_GUID      | GUID format is invalid            | Provide a valid GUID string           |

  **Error Response Example (Not a Member):**

  | Parameter        | Type   | Description                                                                                         |
  | ---------------- | ------ | --------------------------------------------------------------------------------------------------- |
  | errorCode        | String | Example: `"ERR_NOT_A_MEMBER"`                                                                       |
  | errorDescription | String | Example: `"The user with UID cometchat-uid-2 is not a member of group with GUID Cometchat-guid-1."` |

  **Error Response Example (Permission Denied):**

  | Parameter        | Type   | Description                                                 |
  | ---------------- | ------ | ----------------------------------------------------------- |
  | errorCode        | String | Example: `"ERR_PERMISSION_DENIED"`                          |
  | errorDescription | String | Example: `"Only the owner or admin can update this group."` |

  **Error Response Example (Group Not Found):**

  | Parameter        | Type   | Description                                                |
  | ---------------- | ------ | ---------------------------------------------------------- |
  | errorCode        | String | Example: `"ERR_GUID_NOT_FOUND"`                            |
  | errorDescription | String | Example: `"Group with the specified GUID does not exist."` |
</Accordion>

<Accordion title="Sample Payload - getGroup() Request (Pre-Update Fetch)">
  **Method Signature:**

  | Parameter | Type                          | Description                                              |
  | --------- | ----------------------------- | -------------------------------------------------------- |
  | GUID      | String                        | Group identifier to fetch. Example: `"cometchat-guid-1"` |
  | onSuccess | (Group) -> Void               | Success callback with Group object                       |
  | onError   | (CometChatException?) -> Void | Error callback with exception details                    |

  **Request Parameters:**

  | Parameter | Type   | Description                                                                |
  | --------- | ------ | -------------------------------------------------------------------------- |
  | guid      | String | The unique identifier of the group to fetch. Example: `"Cometchat-guid-1"` |

  **Use Case:**

  | Step | Action            | Description                                                   |
  | ---- | ----------------- | ------------------------------------------------------------- |
  | 1    | Fetch group       | Call `CometChat.getGroup(GUID:)` to get current group details |
  | 2    | Modify properties | Update desired properties on the returned Group object        |
  | 3    | Update group      | Call `CometChat.updateGroup(group:)` with modified object     |
</Accordion>

<Accordion title="Sample Payload - getGroup() Error Response">
  **Error Callback Parameter:**

  | Parameter | Type                | Description                             |
  | --------- | ------------------- | --------------------------------------- |
  | error     | CometChatException? | Error object containing failure details |

  **Error Response Example:**

  | Parameter        | Type   | Description                                                                                         |
  | ---------------- | ------ | --------------------------------------------------------------------------------------------------- |
  | errorCode        | String | Example: `"ERR_NOT_A_MEMBER"`                                                                       |
  | errorDescription | String | Example: `"The user with UID cometchat-uid-2 is not a member of group with GUID Cometchat-guid-1."` |

  **Common getGroup() Error Codes:**

  | Error Code            | Description                       |
  | --------------------- | --------------------------------- |
  | ERR\_NOT\_LOGGED\_IN  | User is not logged in             |
  | ERR\_GUID\_NOT\_FOUND | Group does not exist              |
  | ERR\_NOT\_A\_MEMBER   | User is not a member of the group |
  | ERR\_INVALID\_GUID    | GUID format is invalid            |
</Accordion>

***

## Real-time Events

When a group is updated, all members receive the `onGroupUpdated` event via `CometChatGroupDelegate`:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    extension YourClass: CometChatGroupDelegate {
        func onGroupUpdated(action: ActionMessage, updatedGroup: Group, updatedBy: User) {
            print("Group updated: \(updatedGroup.name ?? "")")
            print("Updated by: \(updatedBy.name ?? "")")
        }
    }
    ```
  </Tab>
</Tabs>

<Accordion title="Sample Payload - onGroupUpdated Event">
  **Delegate Method Parameters:**

  | Parameter    | Type                                                     | Description                          |
  | ------------ | -------------------------------------------------------- | ------------------------------------ |
  | action       | [ActionMessage](/sdk/ios/receive-message#action-message) | Action message describing the update |
  | updatedGroup | [Group](/sdk/ios/groups-overview#group-properties)       | The updated Group object             |
  | updatedBy    | [User](/sdk/ios/users-overview#user-properties)          | User who performed the update        |

  **ActionMessage Object:**

  | Parameter       | Type                                               | Description                            |
  | --------------- | -------------------------------------------------- | -------------------------------------- |
  | id              | Int                                                | Message ID. Example: `12345`           |
  | messageCategory | MessageCategory                                    | Category. Example: `.action`           |
  | action          | String                                             | Action type. Example: `"groupUpdated"` |
  | actionBy        | [User](/sdk/ios/users-overview#user-properties)    | User who performed action              |
  | actionOn        | [Group](/sdk/ios/groups-overview#group-properties) | Group that was updated                 |
  | sentAt          | Int                                                | Timestamp. Example: `1699800000`       |

  **updatedBy [User](/sdk/ios/users-overview#user-properties) Object:**

  | Parameter | Type                                              | Description                                    |
  | --------- | ------------------------------------------------- | ---------------------------------------------- |
  | uid       | String                                            | User's unique ID. Example: `"cometchat-uid-1"` |
  | name      | String                                            | User's display name. Example: `"John Doe"`     |
  | avatar    | String?                                           | User's avatar URL                              |
  | status    | [UserStatus](/sdk/ios/users-overview#user-status) | Online status. Example: `.online`              |
</Accordion>
