> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Saved Messages

> Every message the logged-in user saved, across all conversations, with unsave by swipe.

`CometChatSavedMessages` lists the messages the logged-in user has saved, across every
conversation. Each row shows where the message came from — the group, or the other person
in a one-to-one chat — with the message's preview and the time it was sent. Swipe a row to
unsave it. Tapping a row hands you the message, so you can open its conversation at it.

![CometChatSavedMessages showing saved messages with their conversation and time](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/docs-overview-saved-messages.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=7cea8909e76ed456c1f3ed641f8c5a21)

***

## Where It Fits

The screen is user-level: it needs no user or group.

> [tab] SwiftUI
>
> ```
> Chats tab ── account menu ── "Saved Messages"
>                                    │ push
>                                    ▼
>                     ┌──────────────────────────────┐
>                     │ CometChatSavedMessages ← here │
>                     └──────────────────────────────┘
>                                    │ onMessageClick(message)
>                                    ▼
>                your chat screen, opened at that message
> ```
>
> It fetches the saved messages when it first appears — up to about a hundred, newest save
> first as the server orders them — and does not fetch again while it stays on screen.

> [tab] UIKit
>
> It fetches the saved messages when its view loads — up to about a hundred, newest save first
> as the server orders them — and does not fetch again on its own. A subclass can call
> `fetchData()` to load again.

***

## Quick Start

> [tab] SwiftUI
>
> Push it from a `NavigationStack`, and open the message's conversation when a row is tapped:
>
> ```swift theme={null}
> struct SavedMessagesScreen: View {
>     var body: some View {
>         CometChatSavedMessages(onMessageClick: { message in
>             openSavedMessage(message)
>         })
>     }
> }
> ```
>
> `onMessageClick` receives the SDK's `BaseMessage`. Its `receiver` is the `Group` it was sent
> to, or the `User` at the other end of a one-to-one chat — the receiver when you sent it,
> the sender otherwise.
>
> The screen uses the system navigation bar with an inline title. With no `onBackClick`, the
> back chevron dismisses the screen. Pass one to handle it yourself:
>
> ```swift theme={null}
> CometChatSavedMessages(onBackClick: { log("back") })
> ```

> [tab] UIKit
>
> Push it, and open the message's conversation when a row is tapped:
>
> ```swift theme={null}
> let saved = CometChatSavedMessages()
>     .set(onMessageClicked: { message in openSavedMessage(message) })
> saved.hidesBottomBarWhenPushed = true
> navigationController?.pushViewController(saved, animated: true)
> ```
>
> `onMessageClicked` receives the SDK's `BaseMessage`. Its `receiver` is the `Group` it was
> sent to, or the `User` at the other end of a one-to-one chat — the receiver when you sent
> it, the sender otherwise.
>
> `CometChatSavedMessages` is a view controller. The back chevron pops the screen.
> `set(onBack:)` replaces that:
>
> ```swift theme={null}
> let saved = CometChatSavedMessages()
>     .set(onBack: { log("back") })
> ```

***

## Rows

> [tab] SwiftUI
>
> Each row is 72 pt: the source's avatar, its name, and a one-line preview — the sender's
> name in bold, a glyph for the message's type, and the text — with the time on the right.
>
> | Message | Title | Prefix |
> | - | - | - |
> | in a group | the group's name | "You:" for yours, the sender's name for anyone else's |
> | one-to-one, received | the sender's name | none |
> | one-to-one, sent by you | the receiver's name | "You:" |
> | a group action | the group's name | none |
>
> The time is when the message was **sent**: a time today, "Yesterday", a weekday within the
> week, then a date. A message with no send time shows none. A deleted message reads "This
> message was deleted".

> [tab] UIKit
>
> Each row is 72 pt: the source's avatar, its name, and a one-line preview — the sender's name
> in bold, a glyph for the message's type, and the text — with the time on the right. In a
> group the prefix is "You:" or the sender's name; in a one-to-one chat it is "You:" on the
> messages you sent, and nothing on the others.
>
> The time is when the message was **sent**, not when it was saved, and the list is in the
> server's order. It is formatted by `dateTimeFormatter`'s buckets when you set one, and the
> Kit's relative format otherwise:
>
> ```swift theme={null}
> CometChatSavedMessages.dateTimeFormatter = MyDateFormatter()
> ```
>
> A message deleted elsewhere stays in the list, reading "This message was deleted".

***

## Unsaving

Swipe a row left and tap **Unsave**. A confirmation asks first; confirming removes the row
at once and shows "Message unsaved". If the server refuses, the row comes back where it
was, with no message. There is no long-press menu on this screen; the swipe is the only way
to unsave.

> [tab] SwiftUI
>
> Saves and unsaves made elsewhere — in an open chat, or on another device — appear here
> without a refresh.

> [tab] UIKit
>
> `onError` is not called for a failed unsave. Hide the swipe with `hideUnsaveOption`:
>
> ```swift theme={null}
> let picker = CometChatSavedMessages()
>     .set(hideUnsaveOption: true)
> ```

***

## Actions and Events

### Callback Methods

> [tab] SwiftUI
>
> | Prop | Signature | When |
> | - | - | - |
> | `onMessageClick` | `(BaseMessage) -> Void` | a row is tapped |
> | `onBackClick` | `(() -> Void)?` | the back chevron is tapped; with none, it dismisses the screen |
>
> There are no load, empty or error callbacks: read `store.uiState`.

> [tab] UIKit
>
> | Setter | Signature | When |
> | - | - | - |
> | `set(onMessageClicked:)`, `set(onMessageClick:)` | `(BaseMessage) -> Void` | a row is tapped |
> | `set(onBack:)`, `set(onBackClick:)` | `() -> Void` | the back chevron is tapped; with none, it pops |
> | `set(onLoad:)` | `([BaseMessage]) -> Void` | the rows load; with `[]` when none are saved |
> | `set(onEmpty:)` | `() -> Void` | no messages are saved |
> | `set(onError:)` | `(CometChatException) -> Void` | the load fails — not an unsave |
>
> ```swift theme={null}
> let saved = CometChatSavedMessages()
>     .set(onLoad: { messages in log("\(messages.count) saved") })
>     .set(onEmpty: { log("nothing saved") })
>     .set(onError: { error in log(error) })
> ```

### SDK Events (Real-Time, Automatic)

The screen loads once, and stays live through its own SDK listener and the Kit's events: a
save or unsave made anywhere in the app appears without a refresh.

> [tab] SwiftUI
>
> There is no pull-to-refresh.

> [tab] UIKit
>
> There is no pull-to-refresh, and no refresh on reconnect.

***

## Functionality

> [tab] SwiftUI
>
> | Prop | Type | Default |
> | - | - | - |
> | `store` | `SavedMessagesStore?` | `nil` |
> | `textFormatters` | `[any CometChatTextFormatter]?` | `[CometChatMentionsFormatter()]` |
> | `imageSource` | `any ImageSource` | `CometChatSharedImageSource()` |
> | `style` | `CometChatSavedMessagesStyle` | |
> | `onBackClick` | `(() -> Void)?` | dismisses the screen |
> | `hideBackIcon` | `Bool` | `false` |
> | `hideLoadingState`, `hideEmptyState`, `hideErrorState` | `Bool` | `false` |

> [tab] UIKit
>
> | Method or property | Type | Does |
> | - | - | - |
> | `set(textFormatters:)` | `[any CometChatTextFormatter]` | text formatters for the previews |
> | `set(style:)`, `style` | `SavedMessagesStyle` | the screen's style |
> | `set(hideUnsaveOption:)`, `hideUnsaveOption` | `Bool` | hides the unsave swipe |
> | `dateTimeFormatter` | `(any CometChatDateTimeFormatter)?` | formats each row's time |
> | `listItemCellClass` | `AnyClass` | the row's cell class |
>
> The request is fixed: there is no request builder.

***

## States

| State | Shows |
| - | - |
| loading | ten shimmer rows |
| content | the rows |
| empty | a bookmark, "No saved messages yet" and "Save messages to keep them handy whenever you need them." |
| error | "Oops!" and "Something went wrong. Please try again." — no retry |

> [tab] SwiftUI
>
> Hide a state with `hideLoadingState`, `hideEmptyState` or `hideErrorState`.

> [tab] UIKit
>
> Each state reports to a callback: `onLoad(messages)` for content, `onEmpty()` with
> `onLoad([])` for empty and `onError(exception)` for error.

***

## Custom View Slots

> [tab] SwiftUI
>
> Replace any state. The error view receives no retry action — there is no retry on this
> screen:
>
> ```swift theme={null}
> CometChatSavedMessages(
>     loadingView: { AnyView(MySpinner()) },
>     emptyView: { AnyView(MyEmptyState()) },
>     errorView: { AnyView(Text("Could not load your saved messages")) }
> )
> ```
>
> Or for every Saved Messages screen in a subtree. An initialiser argument wins:
>
> ```swift theme={null}
> MyAppRoot()
>     .cometChatSavedMessagesEmptyView { MyEmptyState() }
>     .cometChatSavedMessagesHidden([.loadingState])
> ```
>
> Replace the whole row, or one part of it. Each slot receives a `SavedMessageItem` — the
> message as a value, its source's title and avatar, its preview and its send time:
>
> ```swift theme={null}
> CometChatSavedMessages(
>     subtitleView: { item in AnyView(Text(item.preview.text).italic()) },
>     trailingView: { item in AnyView(Image(systemName: "bookmark.fill")) }
> )
> ```
>
> `itemView` replaces the whole row, and the other four are then not used.
>
> | Slot | Replaces | Modifier |
> | - | - | - |
> | `itemView` | the whole row | `.cometChatSavedMessageItemView` |
> | `leadingView` | the avatar | `.cometChatSavedMessageLeadingView` |
> | `titleView` | the title | `.cometChatSavedMessageTitleView` |
> | `subtitleView` | the preview | `.cometChatSavedMessageSubtitleView` |
> | `trailingView` | the time | `.cometChatSavedMessageTrailingView` |
> | `loadingView` | the loading state | `.cometChatSavedMessagesLoadingView` |
> | `emptyView` | the empty state | `.cometChatSavedMessagesEmptyView` |
> | `errorView` | the error state | `.cometChatSavedMessagesErrorView` |
>
> The modifier `.cometChatSavedMessagesHidden` hides states for a subtree.

> [tab] UIKit
>
> Replace a state's view with `set(loadingView:)`, `set(emptyView:)` or `set(errorView:)`.
> There are no row slots: set `listItemCellClass` to a subclass of `CometChatSavedMessageListItem`.

***

## Advanced Methods

### Store Access

> [tab] SwiftUI
>
> `SavedMessagesStore` loads and holds the rows. Pass your own to read its state — `uiState`,
> `messages`, `count` — or to show fixed rows in a preview:
>
> ```swift theme={null}
> #Preview {
>     NavigationStack {
>         CometChatSavedMessages(store: SavedMessagesStore(seeded: .content, messages: SavedMessageItem.samples))
>     }
> }
> ```
>
> A seeded store never fetches. `count` is there for you to show; the screen's title never
> carries it.

> [tab] UIKit
>
> `viewModel` is the screen's `SavedMessagesStore`. Its `messages` are values; `sdkMessage(for:)`
> gives the SDK object.

### Subclassing

> [tab] SwiftUI
>
> `CometChatSavedMessages` is a `View` struct. Customise it with its slots, modifiers and style.

> [tab] UIKit
>
> The view controller and its cell are `open`. Override `defaultSetup()`,
> `setupStyle()`, `updateTitle()`, `fetchData()`, `reloadData()`, the state views and the table
> methods — or replace the cell:
>
> ```swift theme={null}
> final class CountedSavedMessages: CometChatSavedMessages {
>     override func updateTitle() {
>         title = "Saved (\(viewModel.count))"
>     }
>
>     override func renderCurrentState() {
>         super.renderCurrentState()
>         updateTitle()
>     }
> }
>
> final class MySavedCell: CometChatSavedMessageListItem {}
>
> @MainActor func makeSavedMessages() -> CometChatSavedMessages {
>     let saved = CountedSavedMessages()
>     saved.listItemCellClass = MySavedCell.self
>     return saved
> }
> ```

***

## Accessibility

* Each row is one element: the source's name, then the preview and the time.
* The swipe action reads "Unsave".
* The empty and error art is decorative; their titles are headers.

***

## Style

> [tab] SwiftUI
>
> `CometChatSavedMessagesStyle` is sparse: set only what you change.
>
> | Property | Default |
> | - | - |
> | `backgroundColor` | `background1` |
> | `titleColor`, `titleFont` | `textPrimary`, `heading4Bold` — below iOS 26 only; on Liquid Glass the bar's title is the system's |
> | `backIcon`, `backIconTint` | `chevron.backward`, `iconTintPrimary` |
> | `loadingStateSurfaceColor` | `background3` |
> | `emptyStateIcon`, `errorStateIcon` | the bookmark, the error art |
> | `emptyStateStyle`, `errorStateStyle` | `heading3Bold` / `bodyRegular`; the empty icon `neutral300` |
> | `unsaveOptionIcon`, `unsaveActionBackgroundColor` | the bookmark-add glyph, `error` — the swipe |
> | `itemStyle` | a `SavedMessageListItemStyle`: background, title, subtitle, glyph tint, avatar and date |
>
> ```swift theme={null}
> var style = CometChatSavedMessagesStyle()
> style.unsaveActionBackgroundColor = .orange
> style.itemStyle = SavedMessageListItemStyle(titleColor: .indigo, dateStyle: DateStyle(textColor: .gray))
>
> CometChatSavedMessages(style: style)
> ```

> [tab] UIKit
>
> Set the static default for every screen, or one screen's `style`:
>
> ```swift theme={null}
> CometChatSavedMessages.style.unsaveActionBackgroundColor = .systemOrange
>
> let saved = CometChatSavedMessages()
> saved.style.listItemTitleTextColor = .systemIndigo
> saved.style.dateColor = .systemGray
> ```
>
> | Property | Default |
> | - | - |
> | `backgroundColor` | `background1` |
> | `titleColor`, `titleFont` | `textPrimary`, 17 bold — below iOS 26 only |
> | `navigationBarItemsTintColor` | `iconTintPrimary` — the chevron |
> | `listItemTitleTextColor`, `listItemTitleFont` | `textPrimary`, `heading4Medium` |
> | `listItemSubTitleTextColor`, `listItemSubTitleFont` | `textSecondary`, `bodyRegular` |
> | `messageTypeImageTint` | `iconTintSecondary` |
> | `dateColor`, `dateFont` | `textSecondary`, `caption1Regular` |
> | `avatarBackgroundColor`, `avatarTextColor` | `extendedPrimary100`, `primary` |
> | `unsaveActionBackgroundColor` | `error` |
> | `emptyTitle…`, `emptySubTitle…`, `errorTitle…`, `errorSubTitle…` | `heading3Bold` / `bodyRegular` |
> | `shimmerColor1`, `shimmerColor2` | `background3`, `background4` |
>
> `largeTitleColor`, `largeTitleFont`, the six `retryButton…` properties, `tableViewSeparator`
> and the five selection properties have no effect: this screen has no large title, no retry,
> no separators and no selection.

***

## Next Steps

> [card] [Pinned Messages](https://www.cometchat.com/docs/ui-kit/ios/v6/pinned-messages.md)
>
> The messages pinned in one conversation

> [card] [Message List](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md)
>
> Save and unsave messages from the list's menu

> [card] [Pin and Save Messages](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-pin-and-save-messages.md)
>
> Build pinning and saving end to end

> [card] [Component Styling](https://www.cometchat.com/docs/ui-kit/ios/v6/component-styling.md)
>
> Style every component


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.