---
source_url: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/create
title: Create channels
updated_at: 2026-06-04T11:09:41.724Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Create channels

:::tip Channel naming
Before creating channels, take the time to carefully plan your [naming strategy](https://www.pubnub.com/docs/general/channels/channel-naming). Stick to consistent naming conventions and structure your channels thoughtfully. This preparation helps you avoid increased complexity, performance bottlenecks, and scalability issues, ensuring your app remains manageable and efficient as it grows.
:::

Create channels ([Channel](https://www.pubnub.com/docs/chat/swift-chat-sdk/learn/chat-entities/channel) objects) of one of these types:

* [Direct (1:1)](#create-direct-channel)
* [Group](#create-group-channel)
* [Public](#create-public-channel)

:::note Requires App Context
To store data about channels, you must [enable App Context](https://youtu.be/9UEoSlngpYI) for your app's keyset in the [Admin Portal](https://admin.pubnub.com/).
:::

:::warning No support for channel groups
Chat SDKs don't support channel groups. We recommend using a [Core SDK](https://www.pubnub.com/docs/sdks) to manage [channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups).
:::

## Create direct channel

Direct channels enable private 1:1 conversations. Use cases include personal conversations and professional collaboration.

`createDirectConversation()` performs these actions:

1. Creates a channel with the `direct` type
2. Sets [channel membership](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/membership) for the channel owner
3. [Invites](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/invite#invite-one-user) the other user (generates an [invite event](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/custom-events#events-for-channel-initations))

If a conversation between the two users already exists, the method returns that existing channel.

:::note Receive messages
Call [onMessageReceived()](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/watch) to start receiving messages on the channel (closure-based), or use [channel.stream.messages()](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/watch) for an `AsyncStream`-based approach.
:::

### Method signature

This method takes the following parameters:

```swift
chat.createDirectConversation(
    invitedUser: UserImpl,
    channelId: String? = nil,
    channelName: String? = nil,
    channelDescription: String? = nil,
    channelCustom: [String: JSONCodableScalar]? = nil,
    channelStatus: String? = nil,
    membershipCustom: [String: JSONCodableScalar]? = nil
) async throws -> CreateDirectConversationResult<ChannelImpl, MembershipImpl>
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| invitedUser | UserImpl | Yes |  | User that you invite to join a channel. |
| channelId | String | Optional | `Automatically generated ID` | ID of the direct channel. The channel ID is created automatically by a hashing function that takes the string of two user names joined by `&`, computes a numeric value based on the characters in that string, and adds the `direct` prefix in front. For example, `direct.1234567890`. You can override this default value by providing your own ID. |
| channelName | String | Optional |  | Display name for the channel. If you don't provide the name, the channel will get the same name as [id](https://www.pubnub.com/docs/chat/swift-chat-sdk/learn/chat-entities/channel) (value of `channelId`). |
| channelDescription | String | Optional |  | Additional details about the channel. |
| channelCustom | [String: | Optional |  | Any custom properties or metadata associated with the channel in the form of a JSON. Values must be scalar only; arrays or objects are not supported. [App Context filtering language](https://www.pubnub.com/docs/general/metadata/filtering) doesn’t support filtering by custom properties. |
| channelStatus | String | Optional |  | Current status of the channel, like `online`, `offline`, or `archived`. |
| membershipCustom | [String: | Optional |  | Any custom properties or metadata associated with the user-channel [membership](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/membership) in the form of a JSON. Values must be scalar only; arrays or objects are not supported. [App Context filtering language](https://www.pubnub.com/docs/general/metadata/filtering) doesn’t support filtering by custom properties. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Output

| Parameter | Description |
| --- | --- |
| `CreateDirectConversationResult`Type: `object` | Returned object containing these fields: `channel`, `hostMembership`, and `inviteeMembership`. |
| → `channel`Type: [ChannelImpl](https://www.pubnub.com/docs/chat/swift-chat-sdk/learn/chat-entities/channel) | Returned object containing the updated channel metadata. |
| → `hostMembership`Type: [MembershipImpl](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/membership) | Returned object containing the updated host (channel owner) metadata. |
| → `inviteeMembership`Type: `MembershipImpl` | Returned object containing the updated data of the invited user. |

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

Invite `agent-007` to a 1:1 conversation to talk about `customer XYZ`.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  if let agent007 = try await chat.getUser(userId: "agent-007") {
    let conversation = try await chat.createDirectConversation(invitedUser: agent007, channelCustom: ["purpose": "customer XYZ"])
    debugPrint("Direct conversation created with channel ID: \(conversation.channel.id)")
    debugPrint("Host membership: \(conversation.hostMembership)")
    debugPrint("Invitee membership: \(conversation.inviteeMembership)")
  } else {
    debugPrint("User not found")
  }
}
```

## Create group channel

Group channels enable multi-user conversations for team collaboration and community building. Access requires an invitation.

`createGroupConversation()` performs these actions:

1. Creates a channel with the `group` type
2. Sets channel membership for the channel owner
3. [Invites](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/invite#invite-multiple-users) other users to join

:::note Receive messages
Call [onMessageReceived()](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/watch) to start receiving messages on the channel (closure-based), or use [channel.stream.messages()](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/watch) for an `AsyncStream`-based approach.
:::

### Method signature

This method takes the following parameters:

```swift
chat.createGroupConversation(
    invitedUsers: [UserImpl],
    channelId: String? = nil,
    channelName: String? = nil,
    channelDescription: String? = nil,
    channelCustom: [String: JSONCodableScalar]? = nil,
    channelStatus: String? = nil,
    membershipCustom: [String: JSONCodableScalar]? = nil
) async throws -> CreateGroupConversationResult<ChannelImpl, MembershipImpl>
```

#### Input

| Parameter | Description |
| --- | --- |
| `invitedUsers` *Type: `[UserImpl]`Default: n/a | Users that you invite to join a channel. |
| `channelId`Type: `String`Default: Automatically generated ID | ID of the group channel. The channel ID is created automatically using the [v4 UUID generator](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)). You can override it by providing your own ID. |
| `channelName`Type: `String`Default: n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as [id](https://www.pubnub.com/docs/chat/swift-chat-sdk/learn/chat-entities/channel) (value of `channelId`). |
| `channelDescription`Type: `String`Default: n/a | Additional details about the channel. |
| `channelCustom`Type: `[String: JSONCodableScalar]`Default: n/a | Any custom properties or metadata associated with the channel in the form of a JSON. Values must be scalar only; arrays or objects are not supported. [App Context filtering language](https://www.pubnub.com/docs/general/metadata/filtering) doesn’t support filtering by custom properties. |
| `channelStatus`Type: `String`Default: n/a | Current status of the channel, like `online`, `offline`, or `archived`. |
| `membershipCustom`Type: `[String: JSONCodableScalar]`Default: n/a | Any custom properties or metadata associated with the user-channel [memberships](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/membership) in the form of a JSON. Values must be scalar only; arrays or objects are not supported. [App Context filtering language](https://www.pubnub.com/docs/general/metadata/filtering) doesn’t support filtering by custom properties. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Output

| Parameter | Description |
| --- | --- |
| `CreateGroupConversationResult`Type: `object` | Returned object containing these fields: `channel`, `hostMembership`, and `inviteeMemberships`. |
| → `channel`Type: `ChannelImpl` | Returned object containing the updated channel metadata. |
| → `hostMembership`Type: `MembershipImpl` | Returned object containing the updated host (channel owner) data. |
| → `inviteeMemberships`Type: `[MembershipImpl]` | Returned object containing the updated metadata of the invited users. |

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

Create a group conversation and invite `agent-007` and `agent-008` to have weekly syncs on `customer XYZ`.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  let agent007 = try await chat.getUser(userId: "agent-007")
  let agent008 = try await chat.getUser(userId: "agent-008")
    
  if let agent007, let agent008 {
    let conversation = try await chat.createGroupConversation(invitedUsers: [agent007, agent008], channelCustom: ["purpose": "customer XYZ"])
    debugPrint("Group conversation created with channel ID: \(conversation.channel.id)")
    debugPrint("Host membership: \(conversation.hostMembership)")
    debugPrint("Invitee memberships: \(conversation.inviteeMemberships)")
  } else {
    debugPrint("One or more users not found")
  }
}
```

## Create public channel

Public channels are open to anyone without invitation. Use cases include Q&A forums, knowledge sharing, and live event chat.

:::warning Supported features
Public channels do not support [typing indicators](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/typing-indicator) or [read receipts](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/messages/read-receipts). These features are impractical for large audiences.
:::

`createPublicConversation()` creates a channel with the `public` type and the specified metadata.

:::note Receive messages
Call [onMessageReceived()](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/watch) to start receiving messages on the channel (closure-based), or use [channel.stream.messages()](https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/channels/watch) for an `AsyncStream`-based approach.
:::

### Method signature

This method takes the following parameters:

```swift
chat.createPublicConversation(
    channelId: String? = nil,
    channelName: String? = nil,
    channelDescription: String? = nil,
    channelCustom: [String: JSONCodableScalar]? = nil,
    channelStatus: String? = nil
) async throws -> ChannelImpl
```

#### Input

| Parameter | Description |
| --- | --- |
| `channelId`Type: `String`Default: Automatically generated UUIDv4 | ID of the public channel. The channel ID is created automatically using the [v4 UUID generator](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)). You can override it by providing your own ID. |
| `channelName`Type: `String`Default: n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as [id](https://www.pubnub.com/docs/chat/swift-chat-sdk/learn/chat-entities/channel) (value of `channelId`). |
| `channelDescription`Type: `String`Default: n/a | Additional details about the channel. |
| `channelCustom`Type: `[String: JSONCodableScalar]`Default: n/a | Any custom properties or metadata associated with the channel in the form of a JSON. Values must be scalar only; arrays or objects are not supported. [App Context filtering language](https://www.pubnub.com/docs/general/metadata/filtering) doesn’t support filtering by custom properties. |
| `channelStatus`Type: `String`Default: n/a | Current status of the channel, like `online`, `offline`, or `archived`. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Output

| Parameter | Description |
| --- | --- |
| `ChannelImpl` | Object returning the created channel metadata. |

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

Create a public `ask-support` channel.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  let publicChannel = try await chat.createPublicConversation(channelName: "ask-support")
  debugPrint("Public conversation created with channel ID: \(publicChannel.id)")
  debugPrint("Channel custom fields: \(String(describing: publicChannel.custom))")
}
```