Skip to main content
Quick Reference for AI Agents & Developers
  • Create group: Group(guid:name:groupType:password:)CometChat.createGroup(group:onSuccess:onError:)
  • Create with members: CometChat.createGroupWithMembers(group:members:banMembers:onSuccess:onError:)
  • Group types: .public, .private, .password
  • Required fields: GUID, name, groupType
  • Optional: password (required for .password type), icon, description, metadata, tags
  • Related: Join Group · Retrieve Groups · Groups Overview

Group Class

The Group class represents a CometChat group with all its properties.

Group Initializers

InitializerDescription
Group(guid:name:groupType:password:)Basic initializer
Group(guid:name:groupType:password:icon:description:)Full initializer
// Basic Initializer
let group = Group(guid: "group123", name: "My Group", groupType: .public, password: nil)

// Full Initializer
let group = Group(guid: "group123", name: "My Group", groupType: .password, password: "secret123", icon: "https://example.com/icon.png", description: "A test group")

Group Properties

PropertyTypeEditableDescription
guidStringNo*Unique group identifier
nameString?YesGroup display name
groupTypeGroupTypeNo.public, .private, .password
passwordString?NoPassword (for .password type)
iconString?YesGroup icon URL
groupDescriptionString?YesGroup description
ownerString?YesUID of group owner
metadata[String: Any]?YesCustom metadata dictionary
createdAtIntNoCreation Unix timestamp
updatedAtIntNoLast update Unix timestamp
hasJoinedBoolNoIs logged-in user a member
joinedAtIntNoWhen user joined (timestamp)
membersCountIntNoTotal number of members
scopeMemberScopeYesUser’s scope in group
tags[String]YesArray of group tags
* guid is specified at creation and cannot be edited later
Group Object Properties:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-public-1772113094"
nameString?Group display name. Example: "Test Public Group"
groupTypeGroupTypeType of group. Example: .public
iconString?URL to the group’s icon image. Example: nil
groupDescriptionString?Description of the group. Example: nil
ownerString?UID of the group owner. Example: "cometchat-uid-2"
membersCountIntTotal number of members. Example: 1
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113095
scopeMemberScopeUser’s scope in the group. Example: .admin
createdAtIntUnix timestamp when group was created. Example: 1772113094
updatedAtIntUnix timestamp of last update. Example: 0
tags[String]Array of tags. Example: []
metadata[String: Any]?Custom metadata dictionary. Example: [:]
Creator is automatically assigned .admin scope with hasJoined = true

GUID Requirements

RequirementDescription
AlphanumericLetters and numbers allowed
Underscore_ allowed
Hyphen- allowed
SpacesNOT allowed
PunctuationNOT allowed
Special charactersNOT allowed

Create a Group

In other words, as a logged-in user, how do I create a public, private or password-protected group? You can create a group using createGroup() method. This method takes a Group object as a parameter.
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)
})
ParameterDescription
groupAn instance of Group class
GUID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.
Request Parameters:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-public-1772113094"
nameStringGroup display name. Example: "Test Public Group"
groupTypeGroupTypeType of group. Example: .public
passwordString?Password for the group. Example: nil
Success Response (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-public-1772113094"
nameString?Group display name. Example: "Test Public Group"
groupTypeGroupTypeType of group. Example: .public
iconString?URL to the group’s icon image. Example: nil
groupDescriptionString?Description of the group. Example: nil
ownerString?UID of the group owner. Example: "cometchat-uid-2"
membersCountIntTotal number of members. Example: 1
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113095
scopeMemberScopeUser’s scope in the group. Example: .admin
createdAtIntUnix timestamp when group was created. Example: 1772113094
updatedAtIntUnix timestamp of last update. Example: 0
tags[String]Array of tags. Example: []
metadata[String: Any]?Custom metadata dictionary. Example: [:]
Creator is automatically admin with hasJoined = true
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_GUID_ALREADY_EXISTS"
errorDescriptionStringHuman-readable error message. Example: "Group with this GUID already exists"
Request Parameters:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-private-1772113095"
nameStringGroup display name. Example: "Test Private Group"
groupTypeGroupTypeType of group. Example: .private
passwordString?Password for the group. Example: nil
Success Response (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-private-1772113095"
nameString?Group display name. Example: "Test Private Group"
groupTypeGroupTypeType of group. Example: .private
iconString?URL to the group’s icon image. Example: nil
groupDescriptionString?Description of the group. Example: nil
ownerString?UID of the group owner. Example: "cometchat-uid-2"
membersCountIntTotal number of members. Example: 1
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113095
scopeMemberScopeUser’s scope in the group. Example: .admin
createdAtIntUnix timestamp when group was created. Example: 1772113095
updatedAtIntUnix timestamp of last update. Example: 0
tags[String]Array of tags. Example: []
metadata[String: Any]?Custom metadata dictionary. Example: [:]
Private groups require invitation to join. Creator is automatically admin.
Request Parameters:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-password-1772113096"
nameStringGroup display name. Example: "Test Password Group"
groupTypeGroupTypeType of group. Example: .password
passwordStringPassword for the group (required). Example: "test123"
Success Response (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-password-1772113096"
nameString?Group display name. Example: "Test Password Group"
groupTypeGroupTypeType of group. Example: .password
iconString?URL to the group’s icon image. Example: nil
groupDescriptionString?Description of the group. Example: nil
ownerString?UID of the group owner. Example: "cometchat-uid-2"
membersCountIntTotal number of members. Example: 1
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113096
scopeMemberScopeUser’s scope in the group. Example: .admin
createdAtIntUnix timestamp when group was created. Example: 1772113096
updatedAtIntUnix timestamp of last update. Example: 0
tags[String]Array of tags. Example: []
metadata[String: Any]?Custom metadata dictionary. Example: [:]
Password is required for .password type groups. Creator is automatically admin.
Request Parameters:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-detailed-1772113098"
nameStringGroup display name. Example: "Detailed Group"
groupTypeGroupTypeType of group. Example: .public
passwordString?Password for the group. Example: nil
iconString?URL to the group’s icon image. Example: "https://example.com/icon.png"
descriptionString?Description of the group. Example: "A test group with details"
Success Response (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-detailed-1772113098"
nameString?Group display name. Example: "Detailed Group"
groupTypeGroupTypeType of group. Example: .public
iconString?URL to the group’s icon image. Example: "https://example.com/icon.png"
groupDescriptionString?Description of the group. Example: "A test group with details"
ownerString?UID of the group owner. Example: "cometchat-uid-2"
membersCountIntTotal number of members. Example: 1
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113098
scopeMemberScopeUser’s scope in the group. Example: .admin
createdAtIntUnix timestamp when group was created. Example: 1772113098
updatedAtIntUnix timestamp of last update. Example: 0
tags[String]Array of tags. Example: []
metadata[String: Any]?Custom metadata dictionary. Example: [:]
Request Parameters:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-metadata-1772113100"
nameStringGroup display name. Example: "Metadata Group"
groupTypeGroupTypeType of group. Example: .public
metadata[String: Any]Custom metadata dictionary. Example: ["priority": 1, "category": "test"]
tags[String]Array of tags. Example: ["test", "debug"]
Metadata Properties:
ParameterTypeDescription
metadata.priorityIntPriority level of the group. Example: 1
metadata.categoryStringCategory of the group. Example: "test"
Success Response (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-metadata-1772113100"
nameString?Group display name. Example: "Metadata Group"
groupTypeGroupTypeType of group. Example: .public
iconString?URL to the group’s icon image. Example: nil
groupDescriptionString?Description of the group. Example: nil
ownerString?UID of the group owner. Example: "cometchat-uid-2"
membersCountIntTotal number of members. Example: 1
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113100
scopeMemberScopeUser’s scope in the group. Example: .admin
createdAtIntUnix timestamp when group was created. Example: 1772113100
updatedAtIntUnix timestamp of last update. Example: 0
tags[String]Array of tags. Example: ["test", "debug"]
metadata[String: Any]?Custom metadata dictionary. Example: ["category": "test", "priority": 1]

Add Members While Creating a Group

You can create a group and add members at the same time using the createGroupWithMembers() method. This method takes the Group Object, Array of GroupMember Objects to be added & Array of UIDs to be banned.

GroupMember Class

InitializerDescription
GroupMember(UID:groupMemberScope:)Create a group member with UID and scope
// Create group member objects
let member = GroupMember(UID: "user123", groupMemberScope: .participant)

// With different scopes
let admin = GroupMember(UID: "admin-user", groupMemberScope: .admin)
let moderator = GroupMember(UID: "mod-user", groupMemberScope: .moderator)
let participant = GroupMember(UID: "regular-user", groupMemberScope: .participant)
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))")
})
Request Parameters:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-members-1772113101"
nameStringGroup display name. Example: "Group with Members"
groupTypeGroupTypeType of group. Example: .public
members[GroupMember]Array of members to add. Example: 1 member
banMembers[String]Array of UIDs to ban. Example: []
Members to Add:
UIDScopeDescription
cometchat-uid-2.participantRegular member with basic permissions
Success Response ([String: Any] Dictionary):
ParameterTypeDescription
groupGroupThe created group object
members[GroupMember]Array of successfully added members
errors[String: Any]Any errors for specific members
Response - Created Group:
ParameterTypeDescription
guidStringUnique group identifier. Example: "test-members-1772113101"
nameString?Group display name. Example: "Group with Members"
membersCountIntTotal number of members. Example: 2
ownerString?UID of the group owner. Example: "cometchat-uid-2"
Response - Added Members:
UIDScopeStatus
cometchat-uid-2.participantAdded successfully
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_GUID_ALREADY_EXISTS"
errorDescriptionStringHuman-readable error message. Example: "Group with this GUID already exists"

GroupType Enum

ValueDescription
.publicAnyone can join without approval
.privateRequires invitation or approval to join
.passwordRequires password to join

MemberScope Enum

ValueDescription
.adminFull control over group
.moderatorCan manage members and messages
.participantRegular member with basic permissions

Common Error Codes

Error CodeDescriptionResolution
ERR_NOT_LOGGED_INUser is not logged inLogin first using CometChat.login()
ERR_GUID_ALREADY_EXISTSGroup with GUID already existsUse a unique GUID
ERR_INVALID_GUIDInvalid GUID formatUse alphanumeric with underscore/hyphen only
ERR_EMPTY_GROUP_NAMEGroup name is emptyProvide a valid group name
ERR_INVALID_GROUP_TYPEInvalid group typeUse .public, .private, or .password
ERR_PASSWORD_MISSINGPassword required for password groupProvide password for .password type