---
source_url: https://www.pubnub.com/docs/sdks/swift/api-reference/channel-groups
title: Channel Groups API for Swift Native SDK
updated_at: 2026-06-30T11:08:35.022Z
sdk_name: PubNub Swift SDK
sdk_version: 10.1.7
---

> 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


# Channel Groups API for Swift Native SDK

PubNub Swift SDK, use the latest version: 10.1.7

Install:

```bash
Add PubNub via Swift Package Manager or CocoaPods@10.1.7
```

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the PubNub [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function adds channels to a channel group.

### Method(s)

`Adding Channels` is accomplished by using the following method(s) in the Swift SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```swift
func add(
    channels: [String],
    to group: String,
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: `((Result<[String: [String]], Error>) -> Void)?`
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| channels | [String] | Yes |  | List of `channels` to add to the group. |
| to | String | Yes |  | The Channel Group to add the list of channels to. |
| custom | PubNub.RequestConfiguration | Optional | `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| completion | ((Result<(group: | Optional | `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

A `Tuple` containing the channel-group and the `Array` of channels added.

##### Failure

An `Error` describing the failure.

### Sample code

#### Add channels

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```swift
import PubNubSDK

// Initializes a PubNub object with the configuration
let pubnub = PubNub(
  configuration: PubNubConfiguration(
    publishKey: "demo",
    subscribeKey: "demo",
    userId: "myUniqueUserId"
  )
)

// Add channels to a channel group
pubnub.add(
  channels: ["channelSwift", "otherChannel"],
  to: "SwiftGroup"
) { result in
  switch result {
  case let .success(response):
    print("The channel-group `\(response.group)` had the following channels added: \(response.channels)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
```

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function lists all channels in a channel group.

### Method(s)

`Listing Channels` is accomplished by using the following method(s) in the Swift SDK:

```swift
func listChannels(
    for group: String,
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(group: String, channels: [String]), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `for` *Type: StringDefault: n/a | The channel group to list channels on. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<(group: String, channels: [String]), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

A `Tuple` containing the channel-group and the `Array` of its channels.

##### Failure

An `Error` describing the failure.

### Sample code

#### List channels

```swift
// List the channels in a channel group
pubnub.listChannels(for: "family") { result in
  switch result {
  case let .success(response):
    print("The channel-group `\(response.group)` is made of the following channels: \(response.channels)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
```

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes channels from the channel group.

### Method(s)

`Removing Channels` is accomplished by using the following method(s) in the Swift SDK:

```swift
func remove(
    channels: [String],
    from group: String,
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<(group: String, channels: [String]), Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `channels` *Type: [String]Default: n/a | The list of channels to remove from the channel group. |
| `from` *Type: StringDefault: n/a | The channel group to remove channels from. |
| `custom`Type: `PubNub.RequestConfiguration`Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub Configuration or Network Session. |
| `completion`Type: `((Result<(group: String, channels: [String]), Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

A `Tuple` containing the channel-group and the `Array` of channels removed.

##### Failure

An `Error` describing the failure.

### Sample code

#### Remove channels

```swift
// Remove channels from a channel group
pubnub.remove(
  channels: ["channelSwift", "otherChannel"],
  from: "SwiftGroup"
) { result in
  switch result {
  case let .success(response):
    print("The channel-group `\(response.group)` had the following channels removed: \(response.channels)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
```

## List channel groups

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function lists all the channel groups.

### Method(s)

`Listing Channel Groups` is accomplished by using the following method(s) in the Swift SDK:

```swift
func listChannelGroups(
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: `((Result<[String], Error>) -> Void)?`
)
```

| Parameter | Description |
| --- | --- |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<[String], Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

List of all channel-groups.

##### Failure

An `Error` describing the failure.

### Sample code

#### List channel groups

```swift
// List all channel groups
pubnub.listChannelGroups { result in
  switch result {
  case let .success(channelGroups):
    print("List of all channel-groups: \(channelGroups)")
  case let .failure(error):
    print("Failed Channel Groups Response: \(error.localizedDescription)")
  }
}
```

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes the channel group.

### Method(s)

`Deleting Channel Group` is accomplished by using the following method(s) in the Swift SDK:

```swift
func remove(
    channelGroup: String,
    custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
    completion: ((Result<String, Error>) -> Void)?
)
```

| Parameter | Description |
| --- | --- |
| `channelGroup` *Type: StringDefault: n/a | The channel group to delete. |
| `custom`Type: [PubNub.RequestConfiguration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration)Default: `PubNub.RequestConfiguration()` | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the [Request Configuration](https://www.pubnub.com/docs/sdks/swift/api-reference/configuration#request-configuration) section. |
| `completion`Type: `((Result<String, Error>) -> Void)?`Default: `nil` | The async `Result` of the method call. |

#### Completion handler result

##### Success

The channel-group that was removed.

##### Failure

An `Error` describing the failure.

### Sample code

#### Delete channel group

```swift
// Remove a channel group
pubnub.remove(channelGroup: "SwiftGroup") { result in
  switch result {
  case let .success(channelGroup):
    print("The channel-group that was removed: \(channelGroup)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.