Delete channels
Chat SDK lets you remove an existing channel (with or without deleting its historical data from the App Context storage) using one of these methods: delete()
and deleteChannel()
.
Both of these methods give the same output. The only difference is that you call a given method either on the Chat
(deleteChannel()
) or the Channel
(delete()
) 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 delete or not because it's already known.
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Method signature
These methods take the following parameters:
-
delete()
(on theChannel
object)channel.delete(
soft: Bool = false
) async throws -> ChannelImpl? -
deleteChannel()
(on theChat
object)chat.deleteChannel(
id: String,
soft: Bool = false
) async throws -> ChannelImpl?
Input
Parameter | Required in delete() | Required in deleteChannel() | Description |
---|---|---|---|
id Type: String Default: false | No | Yes | Unique channel identifier. |
soft Type: Bool Default: false | No | No | Define if you want to permanently remove channel metadata. The channel metadata gets permanently deleted from the App Context storage by default. If you set this parameter to true , the Channel object gets the deleted status, and you can still restore/get its data. |
Output
Parameter | Description |
---|---|
ChannelImpl? | For hard delete, the method returns nil . For soft delete, it returns an updated channel instance with the status field set to deleted . |
Basic usage
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.
Permanently delete the support
channel metadata.
delete()
// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
try await channel.delete()
} else {
debugPrint("Channel not found")
}
}
Other examples
Archive (soft delete) the channel with the ID of support
, keeping its data in the App Context storage.
delete(soft: true)
// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
let deletionResult = try await channel.delete(soft: true)
debugPrint(String(describing: deletionResult?.id))
debugPrint(String(describing: deletionResult?.status))
} else {
debugPrint("Channel not found")
}
}