SwiftSwift Native Channel Groups API Reference for Realtime Apps

 
These docs are for the new PubNub Swift SDK written purely in Swift. To view the docs for the older version (the PubNub Objective-C SDK wrapper for Swift), have a look here.

Channel Groups allows PubNub developers to bundle thousands of channels into a group that can be identified by name. These Channel Groups can then be subscribed to, receiving data from the many backend-channels the channel group contains.

Learn more about our Channel Groups here


Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function adds a channel to a channel group.
Adding Channels is accomplished by using the following method(s) in the Swift SDK:
 

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

  1. ParameterTypeRequiredDescription
    channels[String]YesList of channels to add to the group.
    toStringYesThe Channel Group to add the list of channels to.
pubnub.add(
  channels: ["channelSwift", "otherChannel"], 
  to: "SwiftGroup"
) { result in
  switch result {
  case let .success(response):
    print("Successful Add Channels Response: \(response)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
GenericServicePayloadResponse(
  message: EndpointResponseMessage.acknowledge, 
  details: [], 
  service: "channel-registry", 
  status: 200, 
  error: false, 
  channels: [:]
)

Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function lists all the channels of the channel group.
Listing Channels is accomplished by using the following method(s) in the Swift SDK:
  1. ParameterTypeRequiredDescription
    forStringYesThe channel group to list channels on.
pubnub.listChannels(for: "family") { result in
  switch result {
  case let .success(response):
    print("Successful List of Channels in Group Response: \(response)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
ChannelListPayload(
  group: "family", 
  channels: [
    "ch1", 
    "ch2", 
    "ch3"
   ]
)

Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function removes the channels from the channel group.
Removing Channels is accomplished by using the following method(s) in the Swift SDK:
  1. ParameterTypeRequiredDescription
    channels[String]YesThe list of channels to remove from the channel group.
    fromStringYesThe channel group to remove channels from.
pubnub.remove(
  channels: ["channelSwift", "otherChannel"], 
  from: "SwiftGroup"
) { result in
  switch result {
  case let .success(response):
    print("Successful Add Channels Response: \(response)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
GenericServicePayloadResponse(
  message: EndpointResponseMessage.acknowledge, 
  details: [], 
  service: "channel-registry", 
  status: 200, 
  error: false, 
  channels: [:]
)
Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function lists all the channel groups.
Listing Channel Groups is accomplished by using the following method(s) in the Swift SDK:
pubnub.listChannelGroups { result in
  switch result {
  case let .success(response):
    print("Successful List Channel Groups Response: \(response)")
  case let .failure(error):
    print("Failed Channel Groups Response: \(error.localizedDescription)")
  }
}
GroupListPayload(
  groups: [
    "group1", 
    "group2", 
    "group3", 
    "group4"
  ]
)

Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function removes the channel group.
Deleting Channel Group is accomplished by using the following method(s) in the Swift SDK:
  1. ParameterTypeRequiredDescription
    channelGroupStringYesThe channel group to delete.
pubnub.delete(channelGroup: "channelSwift") { result in
  switch result {
  case let .success(response):
    print("Successful Add Channels Response: \(response)")
  case let .failure(error):
    print("Failed Add Channels Response: \(error.localizedDescription)")
  }
}
GenericServicePayloadResponse(
  message: EndpointResponseMessage.acknowledge, 
  details: [], 
  service: "channel-registry", 
  status: 200, 
  error: false, 
  channels: [:]
)