Skip to main content
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 · Retrieve Groups · Group Members
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

PropertyTypeDescription
guidStringUnique group identifier (required)
nameString?Group display name (required)
iconString?Group icon URL
groupDescriptionString?Group description
ownerString?UID of the group owner
groupTypegroupTypeType: .public, .private, .password
passwordString?Password for protected groups
metadata[String: Any]?Custom metadata dictionary
createdAtIntCreation Unix timestamp
updatedAtIntLast update Unix timestamp
joinedAtIntWhen current user joined
scopeGroupMemberScopeTypeCurrent user’s scope in group
hasJoinedBoolWhether current user has joined
membersCountIntTotal number of members
tags[String]Array of group tags
isBannedFromGroupBoolWhether current user is banned

Creating a Group Object

// 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"]

Success Response Example

// 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 ?? "")")
})

Group Type Enum

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

GroupMemberScopeType Enum

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

Common Error Codes

Error CodeDescription
ERR_GUID_NOT_FOUNDGroup with specified GUID does not exist
ERR_ALREADY_JOINEDUser has already joined the group
ERR_NOT_A_MEMBERUser is not a member of the group
ERR_WRONG_PASSWORDIncorrect password for protected group
ERR_GROUP_NOT_JOINEDMust join group before performing action
ERR_PERMISSION_DENIEDInsufficient permissions for action