Skip to main content

Delete a channel

Deleting a channel removes the local channel record from the channel list. This does not delete the messages within the channel — only the channel entry is removed.

Delete a single channel

Call delete(completion:) on a channel instance:

swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.delete { success, error in
if success {
print("Channel deleted.")
} else {
print("Failed: \(error?.localizedDescription ?? "unknown error")")
}
}

Delete multiple channels

Call the class method deleteChannels(identifiers:completion:):

swift
import NexconnChatSDK
let id1 = ChannelIdentifier(channelType: .direct, channelId: "user1")
let id2 = ChannelIdentifier(channelType: .group, channelId: "groupId")
BaseChannel.deleteChannels(identifiers: [id1, id2]) { error in
if error == nil {
print("Channels deleted.")
}
}

Alternatively, build an identifiers array and pass it to deleteChannels:completion::

swift
import NexconnChatSDK
let id1 = ChannelIdentifier(channelType: .direct, channelId: "user1")
let id2 = ChannelIdentifier(channelType: .direct, channelId: "user2")
BaseChannel.deleteChannels(identifiers: [id1, id2]) { error in
if error == nil {
print("Channels deleted.")
}
}