---
source_url: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/messages/restore
title: Restore messages
updated_at: 2026-05-22T11:04:33.695Z
---

> 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


# Restore messages

`restore()` recovers soft-deleted messages and their attached files. Hard-deleted messages cannot be restored.

:::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 has the following signature:

```swift
message.restore() async throws -> MessageImpl
```

#### Input

This method doesn't take any parameters.

#### Output

| Parameter | Description |
| --- | --- |
| `MessageImpl` | Object returning the restored [MessageImpl object](https://www.pubnub.com/docs/chat/swift-chat-sdk/learn/chat-entities/message). |

### 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.
:::

Restore a previously soft deleted message with the `16200000000000001` timetoken.

```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) {
      let restoredMessage = try await message.restore()
      debugPrint("Message restored successfully: \(restoredMessage.text)")
    } else {
      debugPrint("Message not found")
    }
  } else {
    debugPrint("Channel not found")
  }
}
```