Skip to main content
CometChatSearch searches conversations and messages together. A search field, a rail of filter chips and two result sections — Chats above, Messages below — each paginating as you scroll.
CometChatSearch showing filter chips and conversation results for a query

Where It Fits

CometChatSearch is the way into everything already said. It is a whole screen with its own field, not a list you embed, and it hands you back an SDK model to navigate with.
Both toolkits read from the same store, including the chip rules and the result mapping, so the SwiftUI and UIKit screens can never disagree about what to show.

Quick Start

That is a working search screen: it debounces your typing, searches both halves, shows three results a section with a “Show More” link, and paginates as you scroll.
Nothing is fetched until there is something to search for. With no text and no chip selected the screen shows its initial state, which is a separate state from “no results” and has its own slot and its own flag.

One half only

The scope gates which halves are requested. It is not section order — sections are always Chats then Messages, and a section with no results is simply absent.

Inside one conversation

uid wins if you set both.
A scoped search is messages only, whatever the search scopes say: there is one conversation, so searching conversations is meaningless. The placeholder changes to name the scope.

Filtering the request

Each closure is called fresh for every fetch, so return a new builder each time rather than capturing one instance. A request builder is consumed by building: one shared instance would hand every page the same pagination cursor.

The Filter Chips

Seven chips, in this order: Unread, Groups, Photos, Videos, Links, Documents, Audio. They belong to four families, and the families are the whole behaviour: Select one chip and the rail collapses to that chip’s family — the other families stop being drawn. Within a family chips combine, so Photos and Videos can both be on. Selecting a filter also lifts the three-row preview and suppresses “Show More”, because a filtered search is already the thing you asked for. Deselecting the last chip restores all seven.

Choosing which chips exist

initialSearchFilter pre-selects one. It is ignored if it is not in searchFilters.

Hiding the rail


Result Sections

Two sections, fixed order: A message row’s kind is decided once, centrally, from the message itself — so a hit with a URL in it renders as a link row in both toolkits, and an action, a card, a custom or an interactive message all render as text rows.
A link row draws its URL as plain, untappable text. The row already has a destination — the message — and a tappable link inside it would give one row two.
Each section pages independently: three rows while you have typed text and no chip, a full page otherwise, with “Show More” on a section that has more.
The matched keyword is highlighted in titles and subtitles, every occurrence, case-insensitively.

Actions and Events

Callback Methods

The two click callbacks hand back SDK models, so you can navigate with them directly. The two load callbacks hand back the value types the rows render, and fire on every emission — including the empty one when the field is cleared.onBack also decides who draws the back button. Leave it nil and the screen relies on the navigation stack it is pushed onto, exactly as a system screen would. Set it and the Kit draws its own chevron in the bar, hides the system’s, and calls your closure.
onError fires only when both halves failed. One half failing is not an error state: that section is simply absent and the other section’s rows show.

Global Events

The screen raises nothing on the event buses. Navigation is yours, through the callbacks or, in UIKit, the delegate.

SDK Events (Real-Time, Automatic)

Search registers no SDK listeners. A result row is a snapshot of the moment it was fetched: a message edited or deleted afterwards keeps its old text until the next search. That is deliberate.
There is nothing to connect or disconnect.

Functionality


Custom View Slots

State views

Four states, four slots. The initial state and the no-results state are separate:
errorView takes no retry argument. The built-in error view ships a real retry button; a view you supply owns its own retry, because you own the view.

Row slots

Eleven slots. The whole conversation row:
…or just the pieces of it:
conversationItemView shadows all four section slots. Supply the whole row and the pieces are not consulted.
Message rows have no pieces — one slot per kind, each replacing the whole row:
A link row asks linkMessageItemView only — it does not fall back to textMessageItemView, even though a link hit is a text message.

Replacing the cell

Rows are replaced through the row slots above.

Common Patterns

Open the right screen from either section

A media picker

Chips only, no text, one family:

Search inside one chat

A messages-only picker

Pass searchScopes: [.messages] and handle onMessageClick, as in Scoping a Search.

Advanced Methods

Driving the Field

Your view owns the text, so a deep link can pre-fill it and a navigation can clear it. Leave it out and the component keeps its own.

Store Access

Supply a SearchStore through searchStore to share state across screens or to seed a preview.

Subclassing

CometChatSearch is a View struct. Customise it with its slots and style.

Objective-C

Objective-C is covered on the UIKit tab.

Style

Liquid Glass

The chip rail is chrome, so on iOS 26 and later it renders as Liquid Glass and the results travel behind it. That is why the rail’s height is a content inset rather than a gap: with nothing moving behind the material there is nothing to refract, and the glass would render as a plain fill. It falls back to an opaque rail automatically on earlier systems and whenever Reduce Transparency is on. You do not opt in or out per component.

Next Steps

Conversations

The list a search result opens

Message List

Where a message result lands

Users

The directory, for starting a new conversation