Manage channel updates
Update channel details and receive events whenever someone updates them.
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Update channel details
You can edit the metadata of an existing channel with update() and updateChannel().
Both of them give the same output. The only difference is that you call a given method either on the Chat (updateChannel()) or the Channel (update()) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the channel ID you want to update or not because it's already known.
Method signature
These methods take the following parameters:
- 
update()(on theChannelobject)1channel.update(
 2 name: String? = nil,
 3 custom: [String: JSONCodableScalar]? = nil,
 4 description: String? = nil,
 5 status: String? = nil,
 6 type: ChannelType? = nil
 7) async throws -> ChannelImpl
- 
updateChannel()(on theChatobject)1chat.updateChannel(
 2 name: String? = nil,
 3 custom: [String: JSONCodableScalar]? = nil,
 4 description: String? = nil,
 5 status: String? = nil,
 6 type: ChannelType? = nil
 7) async throws -> ChannelImpl
Input
| Parameter | Required in update() | Required in updateChannel() | Description | 
|---|---|---|---|
| idType:  StringDefault: n/a | No | Yes | Unique channel identifier. | 
| nameType:  StringDefault: n/a | No | No | Display name for the channel. | 
| customType:  [String: JSONCodableScalar]Default: n/a | No | No | JSON providing custom data about the channel. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties. | 
| descriptionType:  StringDefault: n/a | No | No | Additional details about the channel. | 
| statusType:  StringDefault: n/a | No | No | Tag that categorizes a channel by its state, like archived. | 
| typeType:  ChannelTypeDefault: n/a | No | No | Tag that categorizes a channel by its function, like offtopic. | 
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
| Parameter | Description | 
|---|---|
| ChannelImpl | Object containing the updated channel with its metadata. | 
Sample code
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.
Update the description of the support channel.
- update()
1// Assuming you have a reference of type "ChatImpl" named "chat"
2Task {
3  if let channel = try await chat.getChannel(channelId: "support") {
4    let updatedChannel = try await channel.update(name: "This is the updated description for the support channel")
5    debugPrint("Updated channel: \(channel)")
6  } else {
7    debugPrint("Stopped typing indicator on the 'support' channel")
8  }
9}
Get channel updates
You can receive updates when specific Channel object(s) are edited or removed on other clients using the following methods:
- streamUpdates()checks updates on a single- Channelobject and it's tied to an instance of the- Channelclass.
- streamUpdatesOn()checks updates on a- Channelobject list and it's tied to the- Channelclass.
Both methods return an asynchronous stream which produces a new value whenever someone adds, changes, or removes channel metadata.
Underneath, these methods subscribe the current user to a channel and add an objects event listener to receive all objects events of type channel. These methods also return the unsubscribe function you can invoke to stop receiving objects events and unsubscribe from the channel.
Method signature
These methods take the following parameters:
- 
streamUpdates()1channel.streamUpdates() -> AsyncStream<ChannelImpl?>
- 
streamUpdatesOn()(static)1ChannelImpl.streamUpdatesOn(
 2 channels: [ChannelImpl]
 3) -> AsyncStream<[ChannelImpl]>
Input
| Parameter | Required in streamUpdates() | Required in streamUpdatesOn() | Description | 
|---|---|---|---|
| channelsType:  [ChannelImpl]Default: n/a | No | Yes | A collection of ChannelImplobjects for which you want to get updates. | 
Output
An asynchronous stream that produces updates when the underlying channel(s) change.
Sample code
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.
- 
streamUpdates()Get updates on the supportchannel.- AsyncStream
- Closure
 1// Assuming you have a reference of type "ChatImpl" named "chat"
 2Task {
 3 if let channel = try await chat.getChannel(channelId: "support") {
 4 for await updatedChannel in channel.streamUpdates() {
 5 debugPrint("Updated channel: \(String(describing: updatedChannel))")
 6 }
 7 } else {
 8 debugPrint("Channel 'support' not found")
 9 }
 10}1// Important: Keep a strong reference to the returned "AutoCloseable" object as long as you want
 2// to receive updates. If the "AutoCloseable" is deallocated, the stream will be cancelled,
 3// and no further items will be produced. You can also stop receiving updates manually
 4// by calling the "close()" method on the "AutoCloseable" object.
 5
 6// Assuming you have a reference of type "ChannelImpl" named "channel"
 7autoCloseable = channel.streamUpdates { updatedChannel in
 8 if let updatedChannel = updatedChannel {
 9 debugPrint("Received update for channel with ID: \(updatedChannel.id)")
 10 } else {
 11 debugPrint("No updates received")
 12 }
 13}
- 
streamUpdatesOn()Get updates on the supportandincident-managementchannels.- AsyncStream
- Closure
 1// Assuming you have a reference of type "ChatImpl" named "chat"
 2Task {
 3 if let channel = try await chat.getChannel(channelId: "support") {
 4 for await updatedChannel in ChannelImpl.streamUpdatesOn(channels: [channel]) {
 5 debugPrint("Updated channel: \(String(describing: updatedChannel))")
 6 }
 7 } else {
 8 debugPrint("Channel 'support' not found")
 9 }
 10}1// Important: Keep a strong reference to the returned "AutoCloseable" object as long as you want
 2// to receive updates. If the "AutoCloseable" is deallocated, the stream will be cancelled,
 3// and no further items will be produced. You can also stop receiving updates manually
 4// by calling the "close()" method on the "AutoCloseable" object.
 5
 6// Assuming you have an array of "ChannelImpl" objects named "channels"
 7autoCloseable = ChannelImpl.streamUpdatesOn(channels: channels) { updatedChannels in
 8 for updatedChannel in updatedChannels {
 9 debugPrint("Received update for channel with ID: \(updatedChannel.id)")
 10 }
 11}