---
source_url: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/messages/delete
title: Delete messages
updated_at: 2026-06-16T12:48:53.493Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Delete messages

`delete()` permanently removes a message from Message Persistence or marks it as `deleted` (soft delete).

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) and **Enable Delete-From-History** in the [Admin Portal](https://admin.pubnub.com/).
:::

### Method signature

This method takes the following parameters:

```swift
message.delete(
    soft: Bool = false,
    preserveFiles: Bool = false
) async throws -> MessageImpl?
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| soft | Bool | Optional | `false` | Define if you want to permanently remove message data. By default, the message data gets permanently deleted from Message Persistence. If you set this parameter to `true`, the [Message object](https://www.pubnub.com/docs/chat/swift-chat-sdk/learn/chat-entities/message) gets the `deleted` status and you can still restore/get its data. |
| preserveFiles | Bool | Optional | `false` | Define if you want to keep the files attached to the message or remove them. |

#### Output

| Parameter | Description |
| --- | --- |
| `MessageImpl` | For hard delete, the method returns `nil`. For soft delete, an updated message instance with an added `deleted` action type. |

### Sample code

:::tip 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 message with the `16200000000000001` timetoken from the `support` channel.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  if let channel = try await chat.getChannel(channelId: "support") {
    if let message = try await channel.getMessage(timetoken: 16200000000000001) {
      try await message.delete()
    } else {
      debugPrint("Message not found")
    }
  } else {
    debugPrint("Channel not found")
  }
}
```

### Other examples

Archive (soft delete) the message with the `16200000000000001` timetoken from the `support` channel, keeping its data in Message Persistence.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  if let channel = try await chat.getChannel(channelId: "support") {
    if let message = try await channel.getMessage(timetoken: 16200000000000001) {
      try await message.delete(soft: true)
    } else {
      debugPrint("Message not found")
    }
  } else {
    debugPrint("Channel not found")
  }
}
```