---
source_url: https://www.pubnub.com/docs/sdks/cocoa-swift/api-reference/channel-groups
title: Channel Groups API for Cocoa Swift SDK
description: Learn how to manage channel grouping with the Channel Groups API for Cocoa Swift SDK in PubNub documentation.
updated_at: 2026-11-09T13:29:01.000Z
---

# Channel Groups API for Cocoa Swift SDK

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

This SDK has been replaced by a new PubNub Swift SDK written purely in Swift. Check it out [the Swift SDK docs](https://www.pubnub.com/docs/sdks/swift.md)

[Channel groups](https://www.pubnub.com/docs/pub-sub/subscribe/subscriptions.md) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/pub-sub/subscribe/channels.md) 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/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

This function adds channels to a channel group.

### Method(s)

Use the following method in the Swift SDK:

```swift
open func addChannels(
    _ channels: [String],
    toGroup group: String,
    withCompletion closure: PubNub.PNChannelGroupChangeCompletionBlock? = nil
)
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| channels | [String] | Yes | The channels to add to the channel group. |
| group | String | Yes | The channel group to add the channels to. |
| closure | PNChannelGroupChangeCompletionBlock | Optional | Channel(s) addition completion closure, has one argument - request processing status to report whether data push was successful or not (errorData contains error information in case of failure). |

### Sample code

#### Add channels

```swift
let channelGroup = "family"
```

```swift
self.client.addChannels(["wife"], toGroup: channelGroup, withCompletion: { (status) in

    if !status.isError {

        // Handle successful channels list modification for group.
    }
    else {

        /**
         Handle channels list modification for group error. Check 'category' property
         to find out possible reason because of which request did fail.
         Review 'errorData' property (which has PNErrorData data type) of status
         object to get additional information about issue.

         Request can be resent using: status.retry()
         */
    }
})
```

### Response

Response objects which is returned by client when Add Channels to Group API is used:

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

## 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/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

This function lists all channels in a channel group.

### Method(s)

Use the following method in the Swift SDK:

```swift
open func channelsForGroup(
    _ group: String,
    withCompletion closure: PubNub.PNGroupChannelsAuditCompletionBlock
)
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| group | String | Yes | The channel group for which to list channels. |
| closure | PNGroupChannelsAuditCompletionBlock | Yes | The completion `closure` which will be called when the processing is complete, has two arguments: `result` - in case of successful processing (data field will contain results of channel groups audit operation); `status` - in case of error while processing (`errorData`contains error information). |

### Sample code

#### List channels

```swift
let channelGroup = "family"
```

```swift
self.client.channelsForGroup(channelGroup, withCompletion: { (result, status) in

    if status == nil {

        // Handle downloaded list of chanels using: result.data.channels
    }
    else {

        /**
         Handle channels for group audition error. Check 'category' property
         to find out possible reason because of which request did fail.
         Review 'errorData' property (which has PNErrorData data type) of status
         object to get additional information about issue.

         Request can be resent using: status.retry()
         */
    }
})
```

### Response

Response objects which is returned by client when Add Channels to Group API is used:

```swift
open class PNChannelGroupChannelsData : PNServiceData {

    // Registered channels within channel group.
    open var channels: [String] { get }
}

open class PNChannelGroupChannelsResult : PNResult {

    // Stores reference on channel group's channels list audit request processing information.
    open var data: PNChannelGroupChannelsData { get }
}
```

## 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/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

This function removes channels from a channel group.

### Method(s)

Use the following method in the Swift SDK:

```swift
open func removeChannels(
    _ channels: [String],
    fromGroup group: String,
    withCompletion closure: PubNub.PNChannelGroupChangeCompletionBlock? = nil
)
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| channels | [String] | Yes | The channels to remove from the channel group. If you pass an empty list, the channel group will be removed. |
| group | String | Yes | The channel group from which to remove the channels. |
| closure | PNChannelGroupChangeCompletionBlock | Optional | The completion `closure` which will be called when the processing is complete, has one argument: request processing `status` - in case of error while processing (`errorData`contains error information). |

### Sample code

Removing channels :

```swift
let channelGroup = "family"
```

```swift
self.client.removeChannels(["son"], fromGroup: channelGroup, withCompletion: { (status) in

    if !status.isError {

        // Handle successful channels list modification for group.
    }
    else {

        /**
         Handle channels list modification for group error. Check 'category' property
         to find out possible reason because of which request did fail.
         Review 'errorData' property (which has PNErrorData data type) of status
         object to get additional information about issue.

         Request can be resent using: status.retry();
         */
    }
})
```

### Response

Response objects which is returned by client when Remove Channels to Group API is used:

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

## 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/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

This function deletes a channel group.

### Method(s)

Use the following method in the Swift SDK:

```swift
open func removeChannelsFromGroup(
    _ group: String,
    withCompletion closure: PubNub.PNChannelGroupChangeCompletionBlock? = nil
)
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| group | String | Yes | The channel group to delete. |
| closure | PNChannelGroupChangeCompletionBlock | Optional | The completion `closure` which will be called when the processing is complete, has one argument: request processing `status` - in case of error while processing (`errorData`contains error information). |

### Sample code

Deleting Channel Group :

```swift
let channelGroup = "family"
```

```swift
self.client.removeChannelsFromGroup(channelGroup, withCompletion: { (status) in

    if !status.isError {

        // Handle successful channel group removal.
    }
    else {

        /**
         Handle channel group removal error. Check 'category' property
         to find out possible reason because of which request did fail.
         Review 'errorData' property (which has PNErrorData data type) of status
         object to get additional information about issue.

         Request can be resent using: status.retry();
         */
    }
})
```

### Response

Response objects which is returned by client when Remove Channel Group API is used:

```swift
open class PNAcknowledgmentStatus : PNErrorStatus {

}
```

Last updated at: 2026-11-09T13:29:01.000Z
