Channel Groups API for Swift Native SDK

Channel groups allow PubNub developers to bundle thousands of channels 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.

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

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

This function adds a channel to a channel group.

Method(s)

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

Maximum number of channels

200 channels can be added to the channel group per API call.

func add(
channels: [String],
to group: String,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String: [String]], Error>) -> Void)?`
)
* required
ParameterDescription
channels *
Type: [String]
Default:
n/a
List of channels to add to the group.
to *
Type: String
Default:
n/a
The Channel Group to add the list of channels to.
custom
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 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 channels added.

Failure

An Error describing the failure.

Basic Usage

Add Channels

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.


List Channels

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

This function lists all the channels of the channel group.

Method(s)

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

func listChannels(
for group: String,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<(group: String, channels: [String]), Error>) -> Void)?
)
* required
ParameterDescription
for *
Type: String
Default:
n/a
The channel group to list channels on.
custom
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 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.

Basic Usage

List Channels


Remove Channels

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

This function removes the channels from the channel group.

Method(s)

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

func remove(
channels: [String],
from group: String,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<(group: String, channels: [String]), Error>) -> Void)?
)
* required
ParameterDescription
channels *
Type: [String]
Default:
n/a
The list of channels to remove from the channel group.
from *
Type: String
Default:
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.

Basic Usage

Remove channels


List Channel Groups

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page 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:

func listChannelGroups(
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: `((Result<[String], Error>) -> Void)?`
)
* required
ParameterDescription
custom
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 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.

Basic Usage

List Channel Groups


Delete Channel Group

Requires Stream Controller add-on

This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page 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:

func remove(
channelGroup: String,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<String, Error>) -> Void)?
)
* required
ParameterDescription
channelGroup *
Type: String
Default:
n/a
The channel group to delete.
custom
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 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.

Basic Usage

Delete Channel Group


Last updated on