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

# Delete A Group

> Guide to deleting groups using the CometChat iOS SDK deleteGroup method (admin only).

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

  * **Delete group:** `CometChat.deleteGroup(GUID:onSuccess:onError:)`
  * **Permission:** Only group admin can delete
  * **Related:** [Create Group](/sdk/ios/create-group) · [Leave Group](/sdk/ios/leave-group) · [Groups Overview](/sdk/ios/groups-overview)
</Info>

To delete a group you need to use the `deleteGroup()` method. The user must be an `Admin` of the group they are trying to delete.

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    let GUID = "GUID";

    CometChat.deleteGroup(GUID: GUID, onSuccess: { (response) in

      print("Group deleted successfully.")

    }) { (error) in

      print("Group delete failed with error: " + error!.errorDescription);
    }
    ```
  </Tab>

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

    [CometChat deleteGroupWithGUID:guid onSuccess:^(NSString * response) {

        NSLog(@"Group deleted successfully.");

    } onError:^(CometChatException * error) {

        NSLog(@"Group deletion failed with error: %@",[error errorDescription]);

    }];
    ```
  </Tab>
</Tabs>

The `deleteGroup()` method takes the following parameters:

| Parameter | Description                                    |
| --------- | ---------------------------------------------- |
| GUID      | The GUID of the group you would like to delete |

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

  | Parameter | Type                          | Description                                                      |
  | --------- | ----------------------------- | ---------------------------------------------------------------- |
  | GUID      | String                        | Unique group identifier to delete. Example: `"cometchat-guid-1"` |
  | onSuccess | (String) -> Void              | Success callback with response message                           |
  | onError   | (CometChatException?) -> Void | Error callback with exception details                            |

  **Request Parameters:**

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

  **Prerequisites:**

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

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

  | Parameter | Type   | Description                                                            |
  | --------- | ------ | ---------------------------------------------------------------------- |
  | response  | String | Success confirmation message. Example: `"Group deleted successfully."` |

  **Post-Deletion Effects:**

  | Effect                | Description                                                      |
  | --------------------- | ---------------------------------------------------------------- |
  | Group removed         | Group is permanently deleted from the system                     |
  | Members removed       | All members lose access to the group                             |
  | Messages deleted      | All group messages are permanently deleted                       |
  | Conversations cleared | Group conversations removed from all members' conversation lists |
  | Cannot recover        | This action is irreversible                                      |

  **Real-time Event Triggered:**

  | Event          | Delegate Method          | Description                                                |
  | -------------- | ------------------------ | ---------------------------------------------------------- |
  | onGroupDeleted | `CometChatGroupDelegate` | Notifies all group members that the group has been deleted |

  **onGroupDeleted Event Payload:**

  | Parameter | Type                                               | Description                                                                   |
  | --------- | -------------------------------------------------- | ----------------------------------------------------------------------------- |
  | group     | [Group](/sdk/ios/groups-overview#group-properties) | The deleted group object. See [Group Object](#deletegroup-group-object) below |

  <span id="deletegroup-group-object" />

  **Group Object (in event):**

  | Parameter    | Type                                             | Description                                                  |
  | ------------ | ------------------------------------------------ | ------------------------------------------------------------ |
  | guid         | String                                           | Group's unique ID. Example: `"cometchat-guid-1"`             |
  | name         | String                                           | Group's display name. Example: `"Development Team"`          |
  | icon         | String?                                          | Group's icon URL. Example: `"https://example.com/group.png"` |
  | description  | String?                                          | Group description. Example: `"Team discussions"`             |
  | groupType    | [GroupType](/sdk/ios/groups-overview#group-type) | Group type. Example: `.public`                               |
  | owner        | String                                           | Group owner UID. Example: `"cometchat-uid-1"`                |
  | membersCount | Int                                              | Number of members at deletion. Example: `15`                 |
  | createdAt    | Int                                              | Creation timestamp. Example: `1699700000`                    |
</Accordion>

<Accordion title="Sample Payload - deleteGroup() 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_GROUP_NOT_JOINED"` |
  | errorDescription | String          | Human-readable error message                                   |
  | errorDetails     | \[String: Any]? | Additional error context                                       |

  **Common Error Codes:**

  | Error Code              | Description                                           |
  | ----------------------- | ----------------------------------------------------- |
  | ERR\_NOT\_LOGGED\_IN    | User is not logged in. Call `CometChat.login()` first |
  | ERR\_GUID\_NOT\_FOUND   | Group with specified GUID does not exist              |
  | ERR\_GROUP\_NOT\_FOUND  | Group does not exist in the system                    |
  | ERR\_GROUP\_NOT\_JOINED | User is not a member of the group                     |
  | ERR\_PERMISSION\_DENIED | User is not admin/owner of the group                  |
  | ERR\_INVALID\_GUID      | GUID format is invalid or empty                       |

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

  | Parameter        | Type   | Description                                                                                                                                 |
  | ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
  | errorCode        | String | Example: `"ERR_GROUP_NOT_JOINED"`                                                                                                           |
  | errorDescription | String | Example: `"The user with UID cometchat-uid-2 is not a member of the group with GUID cometchat-guid-1. Please join the group to access it."` |

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

  | Parameter        | Type   | Description                                        |
  | ---------------- | ------ | -------------------------------------------------- |
  | errorCode        | String | Example: `"ERR_PERMISSION_DENIED"`                 |
  | errorDescription | String | Example: `"Only the admin can delete 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>

<Warning>
  **Important Considerations:**

  * Only the group **admin/owner** can delete the group
  * This action is **PERMANENT** and cannot be undone
  * All group data including messages will be **permanently lost**
  * All members will receive the `onGroupDeleted` event via `CometChatGroupDelegate`
</Warning>
