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

# Users

> Alphabetical directory of the users in your app, with sticky letter headers, live presence, live search, filters, selection and item callbacks.

`CometChatUsers` lists the users in your app, grouped under sticky letter headers. Each row
shows the user's avatar with a presence dot and their name. The list paginates as you
scroll, searches the server as you type in its search field, and moves a user who comes
online to the top.

![CometChatUsers showing an alphabetical list of users with letter headers and presence dots](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/docs-overview-users.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=f4fe0355c2f273f443c7655bebf6064e)

***

## Where It Fits

`CometChatUsers` is the directory: the screen a user opens to start a new conversation,
or the picker an "add members" flow embeds.

```
CometChatUsers   ← you are here
        │ onItemClick(user)
        ▼
   your message screen
```

Both toolkits read from the same store, including the letter grouping and the selection,
so the SwiftUI and UIKit lists can never disagree about *what* to show.

***

## Quick Start

> [tab] SwiftUI
>
> ```swift theme={null}
> import CometChatSwiftUI
>
> struct DirectoryScreen: View {
>     var body: some View {
>         CometChatUsers(
>             onItemClick: { user in openChat(with: user) }
>         )
>     }
> }
> ```
>
> That is a working directory: it fetches the first page when it appears, paginates as you
> scroll and keeps presence live. `onItemClick` hands you a `CometChatSDK.User`.
>
> The list draws a system navigation bar with a large "Users" title, so it brings its own
> `NavigationStack`. If your screen already has one, pass `embedsNavigationStack: false`.
> The search field is in the bar and shown by default; pass `hideSearchBox: true` to leave it
> out, or `hideToolbar: true` to hide the bar and the field with it.

> [tab] UIKit
>
> ```swift theme={null}
> import CometChatUIKit
>
> let users = CometChatUsers()
>     .set(onItemClick: { user, indexPath in openChat(with: user) })
> navigationController?.pushViewController(users, animated: true)
> ```
>
> `CometChatUsers` is a `UIViewController`. That is a working directory: it fetches the first
> page when it appears, paginates as you scroll and keeps presence live.
>
> The screen uses large titles, so present it in a `UINavigationController`. The search field
> is in the navigation item and shown by default; `setSearchBoxVisibility(false)` takes it out.
> The title is "Users"; `set(title:)` changes it.
>
> Or observe it with a delegate, which is also how Objective-C uses it:
>
> ```swift theme={null}
> extension UsersCoordinator: CometChatUsersDelegate {
>     func onItemClick(user: User, indexPath: IndexPath) {
>         openChat(with: user)
>     }
> }
> ```

***

## What It Looks Like

Rows are 64 pt high with a 40-pt avatar, the name in `heading4Medium`, and a 14-pt green
presence dot at the avatar's bottom-trailing corner, ringed in the list's background. The
dot shows only for a user who is online and where neither of you has blocked the other.
There are no separators unless you ask for them.

Users are grouped by the first letter of their name, uppercased; a name that does not start
with a letter goes under `#`. The headers — `heading4Medium` in the highlight colour, 20 pt
in — stay pinned as the list scrolls, and stay on while you search. The groups follow the
server's order rather than re-sorting, so a letter can appear twice: a user who comes
online moves to the top and gets their letter's header there.

Loading is a 30-row shimmer. The empty state reads "No Users Available" with "Add contacts
to start conversations and see them listed here."; in UIKit it also shows a person glyph. The
error state reads "Oops!" with "Something went wrong. Please try again." and a **Retry**
button.

***

## Filtering Users

Two builders: one for the list, one used while a search is active.

> [tab] SwiftUI
>
> ```swift theme={null}
> @State private var friends = UsersRequest.UsersRequestBuilder(limit: 30).friendsOnly(true)
> @State private var everyone = UsersRequest.UsersRequestBuilder(limit: 30)
>
> CometChatUsers(
>     usersRequestBuilder: friends,
>     searchRequestBuilder: everyone   // search every user, not only friends
> )
> ```
>
> The list keeps **the instance** you hand it, so hold it in a `@State` or a property rather
> than building a new one in `body`. The first page builds the request and every later page
> continues it. Handing the list a different instance after it has loaded applies from the
> next page on: the rows already loaded stay and nothing is refetched — call
> `store.refreshList()` to start over.

> [tab] UIKit
>
> ```swift theme={null}
> let users = CometChatUsers(usersRequestBuilder: UsersRequest.UsersRequestBuilder(limit: 30).friendsOnly(true))
>     .set(searchRequestBuilder: UsersRequest.UsersRequestBuilder(limit: 30))   // search everyone
> ```
>
> `set(userRequestBuilder:)` does the same as the initialiser. The list keeps **the
> instance**: the first page builds the request and every later page continues it. Set after
> the list has loaded, a builder applies from the next page on — the rows already loaded stay
> and nothing is refetched; call `refreshUsers()` to start over.

> [!WARNING]
>
> With no search builder set, a search writes its keyword into your list builder and it
> **stays there**: clearing the field, pull to refresh and a reconnect then load the list
> filtered by the last keyword. Set a separate search builder to keep your list builder
> clean.

### Filter Recipes

| Goal | Builder |
| - | - |
| Friends only | `.friendsOnly(true)` |
| Online users only | `.set(status: .online)` |
| Hide users you blocked | `.hideBlockedUsers(true)` |
| By role | `.set(roles: ["moderator"])` |
| By tag | `.set(tags: ["vip"])` |
| Specific users | `.set(UIDs: ["alice", "bob"])` |
| Larger pages | `.set(limit: 50)` |

With no builder the list asks for 30 users a page and nothing else.

### Search

The search runs 300 ms after the last keystroke. It asks the server afresh, replaces the
list with the results — still under their letter headers — and pages through them as you
scroll. A keystroke while a search is waiting or in flight cancels it, and its answer is
dropped. A search that finds nobody shows the empty state; one that fails keeps the rows
that were showing.

Clearing the field fetches the first page of the list again at once: the rows are cleared
and the shimmer shows until it answers.

> [tab] SwiftUI
>
> `searchKeyword` puts a keyword in the field and searches for it, when the list first
> appears and whenever the value changes. `searchText` binds the field's text if you want to
> own it.

> [tab] UIKit
>
> `set(searchKeyword:)` puts a keyword in the field and searches for it.

***

## Actions and Events

### Callback Methods

> [tab] SwiftUI
>
> | Prop | Signature | When |
> | - | - | - |
> | `onItemClick` | `(User) -> Void` | a row is tapped outside selection mode |
> | `onItemLongClick` | `(User) -> Void` | a row is long-pressed |
> | `onSelection` | `([User]) -> Void` | the selection bar's tick is tapped |
> | `onSelectionChange` | `([User]) -> Void` | the selection changes — and each time the list appears, with its current value |
> | `onOptionSelected` | `(User, MenuOption) -> Void` | a row option is chosen |
> | `onSearchTextChange` | `(String) -> Void` | the search field's text changes |
> | `onBackPress` | `() -> Void` | the back button is tapped; `nil` dismisses the screen |
> | `onLoad` | `([User]) -> Void` | the list starts showing rows |
> | `onEmpty` | `() -> Void` | the list becomes empty |
> | `onError` | `(CometChatError) -> Void` | the first page, a search or a refresh fails with nothing on screen |

> [tab] UIKit
>
> | Setter | Signature | When |
> | - | - | - |
> | `set(onItemClick:)` | `(User, IndexPath?) -> Void` | a row is tapped outside selection mode |
> | `set(onItemLongClick:)` | `(User, IndexPath) -> Void` | a row is long-pressed |
> | `set(onSelection:)` | `([User]) -> Void` | the selection bar's tick is tapped |
> | `set(onSelectedItemProceed:)` | `([User]) -> Void` | the same tick |
> | `set(onSelectionChange:)` | `([User]) -> Void` | the selection changes — and each time the screen appears, with its current value |
> | `set(onLoad:)` | `([[User]]) -> Void` | the list starts showing rows; the users come grouped by letter section |
> | `set(onEmpty:)` | `() -> Void` | the list becomes empty |
> | `set(onError:)` | `(CometChatException) -> Void` | the first page, a search or a refresh fails with nothing on screen |
> | `set(onBack:)` | `() -> Void` | the back button is tapped |
>
> Each is also a `CometChatUsersDelegate` method, usable from Objective-C — except
> `onSelectedItemProceed`, which has none; `onLoad(users:)` hands the delegate a flat list and
> `onError(error:)` an `NSError`. When both a closure and the delegate are set, both are
> called.
>
> The back button is hidden by default; shown, a tap calls `onBack`, and pops the screen only
> when no handler is set.

> [!WARNING]
>
> Setting `onItemLongClick` — as a closure or, in UIKit, a delegate method — **replaces** the
> options menu: a long press calls it instead. The swipe actions stay.

`onLoad`, `onEmpty` and `onError` are called when the list **changes into** that state,
not for every page — and once more each time the list appears, with the state it is in.

A failure with no rows on screen shows the error state and calls `onError`. **A later page
that fails is silent**: the rows stay, `onError` is not called, and scrolling to the end
again asks again. **Retry** asks for the next page.

### Global Events

The list consumes two Kit events and emits none. When your own screen blocks or unblocks a
user, announce it and the list updates that row in place.

> [tab] SwiftUI
>
> ```swift theme={null}
> CometChatEvents.emitUserEvent(.userBlocked(user: user))
> ```
>
> `.userUnblocked(user:)` is the other.

> [tab] UIKit
>
> ```swift theme={null}
> CometChatUserEvents.ccUserBlocked(user: user)
> ```
>
> `CometChatUserEvents.ccUserUnblocked(user:)` is the other, and
> `CometChatUserEvents.addListener(_:_:)` hears them from anywhere in the Kit.

Everything else the list does is reported through the callbacks above. See
[Events](https://www.cometchat.com/docs/ui-kit/ios/v6/events.md) for the whole bus.

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

No wiring required — the store listens and the list updates itself.

| Event | Effect |
| - | - |
| A listed user comes online | the row is replaced and **moved to the top**, under its own letter header; the list does not scroll |
| A listed user goes offline | the row updates in place |
| Presence for a user either of you has blocked | ignored |
| Presence for a user not listed | ignored — nobody is added |
| A user is blocked or unblocked elsewhere in the Kit | the row updates in place; a blocked user shows no dot |
| Connection restored | the rows are cleared and the first page is fetched again |

> [tab] SwiftUI
>
> When the connection is lost, the connection notice shows.

> [tab] UIKit
>
> The store listens for as long as the screen exists, including while another screen covers
> it.

On a reconnect an active search is replaced by the list, and the field keeps its text.
**Each time the list appears again it loads the next page.** Pull to refresh clears the rows
and fetches the first page; with rows showing there is no shimmer, so the list is blank
until it answers, and a failed refresh shows the error state.

***

## Functionality

> [tab] SwiftUI
>
> | Prop | Type | Default |
> | - | - | - |
> | `store` | `UsersStore?` | a new store |
> | `usersRequestBuilder` | `UsersRequest.UsersRequestBuilder?` | 30 per page |
> | `searchRequestBuilder` | `UsersRequest.UsersRequestBuilder?` | the list builder |
> | `searchKeyword` | `String?` | `nil` — sets the field and searches |
> | `searchText` | `Binding<String>?` | internal state |
> | `style` | `CometChatUsersStyle` | `.init()` |
> | `title` | `String?` | "Users" |
> | `hideToolbar`, `hideTitle`, `hideSearchBox` | `Bool` | `false` |
> | `hideBackIcon`, `hideSeparator` | `Bool` | `true` |
> | `hideStatusIndicator`, `hideStickyHeader` | `Bool` | `false` |
> | `hideLoadingState`, `hideEmptyState`, `hideErrorState` | `Bool` | `false` |
> | `searchPlaceholderText` | `String?` | "Search" |
> | `.cometChatSearchScopes(_:selection:)` | modifier: `[String]`, `Binding<Int>` | no scope buttons |
> | `selectionMode` | `SelectionMode` | `.disabled` |
> | `embedsNavigationStack` | `Bool` | `true` |
> | `imageSource` | `any ImageSource` | the shared cached loader |
>
> `hideTitle` leaves the bar with an empty title. `hideStatusIndicator` also takes the
> presence out of the row's VoiceOver label.
>
> `cometChatUsersHidden(_:)` hides several parts at once. It takes an option set —
> `.toolbar`, `.title`, `.backIcon`, `.searchBox`, `.statusIndicator`, `.stickyHeader`,
> `.separator`, `.loadingState`, `.emptyState`, `.errorState` — and **unions** with the
> `hide*` arguments: a subtree may hide more, never reveal less.
>
> ```swift theme={null}
> CometChatUsers().cometChatUsersHidden([.stickyHeader, .statusIndicator])
> ```
>
> ![Users list without letter headers](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-noStickyHeader.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=474ebc52d6e3fff36e6bcefb6f11aca5)
>
> .stickyHeader
>
> ![Users list without presence dots](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-noStatus.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=7e66e207832708daf93fb7d4d1dc1135)
>
> .statusIndicator

> [tab] UIKit
>
> | Method | Does |
> | - | - |
> | `fetchData()` | the next page |
> | `refreshUsers()` | the first page again, clearing the rows first |
> | `set(searchKeyword:)` | puts a keyword in the field and searches |
> | `getSelectedUsers()`, `clearSelection()`, `selectUser(_:mode:)` | reads and changes the selection |
> | `add(user:)`, `update(user:)`, `remove(user:)` | adds a user at the top, updates one in place, removes one |
> | `setToolbarVisibility(_:)`, `setSearchBoxVisibility(_:)`, `setBackIconVisibility(_:)`, `setUserStatusVisibility(_:)`, `setSeparatorVisibility(_:)`, `setStickyHeaderVisibility(_:)`, `setEmptyStateVisibility(_:)`, `setErrorStateVisibility(_:)`, `setLoadingStateVisibility(_:)` | shows or hides a part; each has a `get…` |
> | `set(hideLoadingState:)`, `set(hideEmptyState:)`, `set(hideErrorState:)` | the same three states, the other way round |
> | `setOverflowMenu(_:)`, `setSearchPlaceholderText(_:)`, `setTitleTextColor(_:)` | the bar |
> | `setSearchInputBackgroundColor(_:)`, `setSearchInputTextColor(_:)`, `setSearchInputCornerRadius(_:)`, `setSearchInputStrokeWidth(_:)`, `setSearchInputStrokeColor(_:)` | the search field |
> | `refreshStyle()` | re-applies `style` after you change it |
> | `renderCurrentState()` | re-shows the current state view after you replace one |
>
> The same switches are properties: `hideUserStatus`, `hideSectionHeader`, `hideSeparator`,
> `hideSearch`, `hideBackButton`, `hideNavigationBar`, `hideLoadingState`, `hideErrorView`,
> `disableEmptyState` and `prefersLargeTitles`. `hideBackButton` and `hideSeparator` are
> `true` by default; `hideSearch` is `false`. Each takes effect whenever you set it, before or
> after the screen loads.
>
> > [!WARNING]
> >
> > `add(user:)` and the store's list operations (`usersStore.addItem`, `removeItem`,
> > `updateItem`, `moveItemToTop`, `clearItems`, `batch`) **never change what the screen is
> > showing**: a user added while the empty state is up stays hidden behind it, and removing
> > the last row with `removeItem` leaves a blank list. `remove(user:)` is the one that shows
> > the empty state when the last row goes.

***

## Custom View Slots

> [tab] SwiftUI
>
> Every slot is available as an initialiser argument and as a modifier that cascades to every
> `CometChatUsers` below it. Supply both and the initialiser argument wins.
>
> ```swift theme={null}
> CometChatUsers(
>     subtitleView: { user in AnyView(MyPresenceText(user)) },
>     trailingView: { user in AnyView(MyRoleLabel(user)) }
> )
> ```
>
> ```swift theme={null}
> .cometChatUserLeadingView { user in MyUserAvatar(user) }
> ```
>
> | Slot | Replaces | Modifier |
> | - | - | - |
> | `itemView` | the whole row | `.cometChatUserItemView { user, isSelected in … }` |
> | `leadingView` | the avatar and its presence dot | `.cometChatUserLeadingView { … }` |
> | `titleView` | the name | `.cometChatUserTitleView { … }` |
> | `subtitleView` | nothing — it adds a line under the name | `.cometChatUserSubtitleView { … }` |
> | `trailingView` | nothing — it adds a trailing column | `.cometChatUserTrailingView { … }` |
> | `loadingView` | the 30-row shimmer | `.cometChatUserLoadingView { … }` |
> | `emptyView` | the empty state | `.cometChatUserEmptyView { … }` |
> | `errorView` | the error state; receives `retry` | `.cometChatUserErrorView { retry in … }` |
> | `overflowMenu` | nothing — the bar's trailing item | — |
>
> Slot closures receive a `ChatUser` — the row's value type (`id`, `name`, `avatarURL`,
> `isOnline`, `isBlockedByMe`, `hasBlockedMe`, `isBlocked`).
>
> ![Default Users list with letter headers, avatars, names and presence dots](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-none.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=c938d105235fd7712a69523dc311e8ea)
>
> **itemView.** Put your own `Button` in the row, and select through the store.
>
> ```swift theme={null}
> @State private var store = UsersStore()
>
> CometChatUsers(
>     store: store,
>     selectionMode: .multiple,
>     itemView: { user, isSelected in
>         AnyView(
>             Button {
>                 if let raw = store.sdkUser(for: user.id) { store.select(raw, mode: .multiple) }
>             } label: {
>                 MyUserRow(user: user, selected: isSelected)
>             }
>         )
>     }
> )
> ```
>
> ![Users list where itemView replaces the entire row with a compact custom layout](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-itemView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=c9595c192d7277f60eefc6b882452866)
>
> **Region slots.**
>
> ```swift theme={null}
> .cometChatUserTitleView { user in Text(user.name).bold() }
> ```
>
> ![Users list with a custom leading view replacing the default avatar](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-leadingView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=d782efebe062e3ae9a2e798c93ede348)
>
> leadingView
>
> ![Users list with a custom title view](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-titleView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=c32e6cfa85f1f8cb46e844f23c682945)
>
> titleView
>
> ![Users list with a subtitle line added under each name](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-subtitleView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=8669caf773142ea55e15b99e829d2ef5)
>
> subtitleView
>
> ![Users list with a trailing view added to each row](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-trailingView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=a09cf77a4d7b3c3ab41373ecdd2eb676)
>
> trailingView
>
> **State views.** `errorView` receives a `retry` closure — call it from your button. It asks
> for the next page, as the built-in Retry does.
>
> ```swift theme={null}
> CometChatUsers(
>     loadingView: { AnyView(MySpinner()) },
>     emptyView:   { AnyView(MyUsersEmptyState()) },
>     errorView:   { retry in AnyView(MyErrorState(onRetry: retry)) }
> )
> ```
>
> ![Users list showing a custom loading view](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-loadingView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=76737a9b9e1028fa0cfb495942b8171c)
>
> loadingView
>
> ![Users list showing a custom empty state](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-emptyView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=6eb61f5e7666734364fb5c6cc49b78d1)
>
> emptyView
>
> ![Users list showing a custom error state with a retry button](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-override-errorView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=f324ccc69de9e099c285f44a9ee98527)
>
> errorView
>
> **overflowMenu.** Adds your own item to the navigation bar's trailing edge. It is replaced
> by the tick while a selection is being made.
>
> ```swift theme={null}
> CometChatUsers(overflowMenu: { AnyView(MyToolbarMenu()) })
> ```

> [tab] UIKit
>
> Each slot receives the SDK `User` — `nil` on a seeded store, which has none.
>
> ```swift theme={null}
> let users = CometChatUsers()
>     .set(subtitle: { user in
>         guard let user else { return UIView() }
>         return MyPresenceLabel(user: user)
>     })
>     .set(trailingView: { user in
>         guard let user else { return UIView() }
>         return MyRoleLabel(user: user)
>     })
> ```
>
> | Setter | Replaces |
> | - | - |
> | `set(listItemView:)` | the whole row |
> | `set(leadingView:)` | the avatar and its presence dot |
> | `set(titleView:)` | the name |
> | `set(subtitle:)` | nothing — it adds a line under the name |
> | `set(trailingView:)` | nothing — it adds a trailing view |
> | `set(loadingView:)`, `set(emptyView:)`, `set(errorView:)` | the three state views — loading is a 30-row shimmer |
> | `listItemCellClass` | the cell class — subclass `CometChatUserListItem` |
> | `setOverflowMenu(_:)` | nothing — the bar's trailing item, replaced by the tick while selecting |
>
> ![Default UIKit Users list with the built-in cell and letter headers](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-uikit-stock.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=c64852b1cb620d17ba7653fbda11633c)
>
> **listItemView.** Give the view its own controls, and select with `selectUser(_:mode:)`.
>
> ```swift theme={null}
> users.set(listItemView: { user in
>     guard let user else { return UIView() }
>     return MyUserRow(user: user)
> })
> ```
>
> **State views.** A custom error view gets no Retry hook; call `fetchData()` from your own
> button.
>
> ```swift theme={null}
> users
>     .set(loadingView: MySpinner())
>     .set(emptyView: MyEmptyState())
>     .set(errorView: MyErrorState())
> ```
>
> ![UIKit Users showing a custom loading view](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-uikit-loadingView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=83670dd9b27853cbcf267dfa4f362273)
>
> loadingView
>
> ![UIKit Users showing a custom empty state](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-uikit-emptyView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=33e73cc98696c1929f74964502369bfd)
>
> emptyView
>
> ![UIKit Users showing a custom error state](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-uikit-errorView.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=e330d8568189d4bdec1b1d3fc749002f)
>
> errorView
>
> **Replacing the cell.**
>
> ```swift theme={null}
> users.listItemCellClass = MyUserCell.self
> ```
>
> ![UIKit Users list rendering a custom UITableViewCell subclass](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/users-uikit-customCell.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=a1059ff3da9dc63e9598f8a58190751e)
>
> `configure(with:style:avatarStyle:statusIndicatorStyle:theme:hideUserStatus:selectionMode:isSelected:showsSeparator:)`
> is the cell's override point, and it resets the slots itself: rows are updated in place,
> which skips `prepareForReuse()`.

> [!WARNING]
>
> A custom row view gets **no** tap, long press, selection, swipe or menu from the Kit —
> the row handles its own interaction.

***

## Menu Options

The list has no options of its own. Give it some and each row shows them twice: as
trailing swipe actions and as a long-press menu.

> [tab] SwiftUI
>
> ```swift theme={null}
> CometChatUsers(
>     addOptions: { user in
>         [MenuOption(id: "message", title: "Message", systemImage: "message")]
>     },
>     onOptionSelected: { user, option in
>         if option.id == "message" { openChat(with: user) }
>     }
> )
> ```
>
> `options` replaces the list's (empty) set; `addOptions` adds to it and is used only when
> `options` is not set.

> [tab] UIKit
>
> ```swift theme={null}
> let users = CometChatUsers()
>     .set(options: { user in
>         [CometChatUserOption(id: "message", title: "Message", icon: UIImage(systemName: "message"),
>                              onClick: { user, indexPath in
>                                  if let user { openChat(with: user) }
>                              })]
>     })
> ```
>
> `set(options:)` replaces the list's (empty) set; `add(options:)` adds to it and is used only
> when `set(options:)` is not. `CometChatUserOption(titleColor:titleFont:iconTint:backgroundColor:onClick:)`
> is also available, and its `onClick` receives the row's index. A full swipe never fires the
> first action.

***

## Common Patterns

### Open a chat on tap

> [tab] SwiftUI
>
> ```swift theme={null}
> @State private var path: [User] = []
>
> NavigationStack(path: $path) {
>     CometChatUsers(embedsNavigationStack: false, onItemClick: { path.append($0) })
>         .navigationDestination(for: User.self) { ChatScreen(user: $0) }
> }
> ```

> [tab] UIKit
>
> See [Quick Start](#quick-start): `set(onItemClick:)` hands you the `User` to open your message screen with.

### Friends only, with your own empty state

> [tab] SwiftUI
>
> ```swift theme={null}
> @State private var friends = UsersRequest.UsersRequestBuilder(limit: 30).friendsOnly(true)
>
> CometChatUsers(
>     usersRequestBuilder: friends,
>     emptyView: { AnyView(NoFriendsYet(onInvite: invite)) }
> )
> ```

> [tab] UIKit
>
> Combine `friendsOnly(true)` in [Filtering Users](#filtering-users) with `set(emptyView:)` in
> [Custom View Slots](#custom-view-slots).

### Scope buttons under the search field

> [tab] SwiftUI
>
> `.cometChatSearchScopes(_:selection:)` puts scope buttons under the search field, in the
> navigation bar, as a New Chat screen switches between Users and Groups. The rows scroll under
> the field and the buttons with the bar's soft edge, and the large title stays sharp.
>
> | Parameter | Type | What it does |
> | - | - | - |
> | `titles` | `[String]` | the buttons, in order (right to left in a right-to-left language); empty shows none |
> | `selection` | `Binding<Int>` | the selected button's index: a tap writes it, and setting it moves the highlight. An index outside `titles` highlights the nearest button |
>
> The buttons show whether or not the field is being searched, and they don't filter the
> search: the list only reports the selection, and what it means is up to you. The modifier
> applies to every list under it, so when your screen swaps one list for the other, the
> buttons stay in the bar with the right one selected.
>
> ```swift theme={null}
> struct NewChatView: View {
>     @State private var page = 0
>
>     var body: some View {
>         NavigationStack {
>             Group {
>                 if page == 0 {
>                     CometChatUsers(embedsNavigationStack: false)
>                 } else {
>                     CometChatGroups(embedsNavigationStack: false)
>                 }
>             }
>             .cometChatSearchScopes(["Users", "Groups"], selection: $page)
>         }
>     }
> }
> ```

> [tab] UIKit
>
> The UIKit list has no scope buttons. Host `CometChatUsers` and `CometChatGroups` under your
> own `UISegmentedControl` — see [New Chat](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-new-chat.md).

### Preview without credentials

> [tab] SwiftUI
>
> ```swift theme={null}
> #Preview {
>     CometChatUsers(store: .init(seeded: .populated(sections, hasMore: false)))
> }
> ```

> [tab] UIKit
>
> Pass your own store to share one, or a seeded one to render a fixed state with no session:
>
> ```swift theme={null}
> let users = CometChatUsers(usersStore: UsersStore(seeded: .populated(sections, hasMore: false)))
> ```

***

## Advanced Methods

### Selection

> [tab] SwiftUI
>
> ```swift theme={null}
> CometChatUsers(
>     selectionMode: .multiple,
>     onSelection: { users in addMembers(Set(users.compactMap(\.uid))) },
>     onSelectionChange: { users in log("\(users.count) selected") }
> )
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let picker = CometChatUsers()
>     .set(selectionMode: .multiple)
>     .set(onSelection: { users in log("\(users.count) picked") })
>     .set(onSelectionChange: { users in log("\(users.count) selected") })
> ```

In a selection mode a tap selects or deselects and does nothing else — `onItemClick` is not
called. In `.multiple` mode a tap toggles the row, with no limit. In `.single` mode a tap
replaces the selection, and a second tap on the selected row **keeps it selected**: a
single selection cannot be emptied by tapping.

> [tab] SwiftUI
>
> Once something is selected the navigation bar shows the count with a cross and a tick. The
> tick calls `onSelection` with the selected users and leaves the selection and the mode as
> they are. The cross clears the selection; the mode stays on, so the next tap selects again.
> The selection lives in the store, so it survives search, paging and refresh — but it is
> **cleared when the list leaves the screen**, for example when you push a screen on top of
> it.

> [tab] UIKit
>
> Once something is selected the navigation bar shows a cross with the number selected beside
> it, and a tick. The title stays. The tick calls `onSelection` and `onSelectedItemProceed`
> with the selected users and leaves the selection and `selectionMode` as they are. The cross
> clears the selection; the mode stays on, so the next tap selects again. Changing
> `selectionMode` keeps the selection. It lives in the store, so it survives search, paging
> and refresh — but it is **cleared when the screen disappears**, for example when you push a
> screen on top of it.
>
> `getSelectedUsers()` reads the selection at any time, `selectUser(_:mode:)` selects by the
> rules above, and `clearSelection()` empties it.

### Store Access

> [tab] SwiftUI
>
> ```swift theme={null}
> @State private var store = UsersStore()
>
> CometChatUsers(
>     store: store,
>     overflowMenu: { AnyView(Button("Reload") { _ = store.refreshList() }) },
>     onItemClick: { user in openChat(with: user) }
> )
> ```
>
> `UsersStore` is the store behind the list. What it exposes:
>
> | Member | Does |
> | - | - |
> | `init(usersRequestBuilder:searchRequestBuilder:)` | a live store; the builders are kept as instances |
> | `init(seeded:selectedIDs:)` | a store pinned to a state, with no session — every fetch, change and selection call is a no-op |
> | `state`, `isSearching`, `connectionNotice` | what the list draws |
> | `onLoad`, `onEmpty`, `onError`, `onSelectionChange` | the callbacks, settable on the store itself |
> | `fetchUsers()` | the next page — nothing while one is in flight or once a page came back empty |
> | `refreshList()` | the first page again, clearing the rows first; returns the request's task |
> | `retry()` | what Retry does: the next page |
> | `search(_:)` | a search 300 ms later; `nil` or `""` returns to the list at once |
> | `setUsersRequestBuilder(_:)`, `setSearchRequestBuilder(_:)` | replace a builder; nothing is cleared or refetched |
> | `selectedUsers`, `selectedIDs`, `isSelected(_:)` | the selection, in the order it was picked |
> | `select(_:mode:)`, `setSelection(_:)`, `clearSelection()` | change the selection |
> | `addItem`, `addItems`, `removeItem`, `removeItem(at:)`, `updateItem(_:matching:)`, `moveItemToTop`, `clearItems`, `batch` | the list operations |
> | `items`, `item(at:)`, `itemCount` | read the rows |
> | `addUserToTop`, `updateUser`, `moveUserToTop`, `removeUser` | the view model's own row changes |
> | `sdkUser(for:)` | the `CometChatSDK.User` behind a row's id |
> | `attachView()`, `detachView()` | what the list calls on appearing and disappearing |
> | `scrollToTopToken` | bumped when a user moves to the top or a refresh lands; the list does not act on it, your view can |
>
> > [!WARNING]
> >
> > The list operations — `addItem`, `addItems`, `removeItem`, `updateItem`, `moveItemToTop`,
> > `clearItems`, `batch` — and `addUserToTop` **never change what the screen is showing**.
> > A user added while the empty state is up stays hidden behind it; removing the last row
> > with `removeItem` leaves a blank list. `removeUser` is the one that shows the empty state
> > when the last row goes.

> [tab] UIKit
>
> `usersStore` is the `UsersStore` the screen draws — the same type the SwiftUI toolkit uses.
> It exposes `fetchUsers()`, `refreshList()`, `retry()`, `search(_:)`,
> `setUsersRequestBuilder(_:)`, `setSearchRequestBuilder(_:)`, the selection
> (`selectedUsers`, `selectedIDs`, `select(_:mode:)`, `setSelection(_:)`, `clearSelection()`),
> the list operations, `sdkUser(for:)` and `scrollToTopToken`, which is bumped when a user
> moves to the top or a refresh lands — the table does not act on it.

### Subclassing

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

> [tab] UIKit
>
> These override points are `open`: `defaultSetup()`, `setupStyle()`, `styleSearchBar()`,
> `registerCells()`, `fetchData()`, `reloadData()`, `showEmptyView()`, `showErrorView()`,
> `showLoadingView()`, `onSearch(text:)`, `onRefreshControlTriggered()`, `tickButtonTapped()`,
> `crossButtonTapped()`, `updateNavigationBarTitleWithCount(_:)` and the table view's
> data-source and delegate methods — `tableView(_:heightForHeaderInSection:)` included.
> `configureOptions(for:indexPath:)` returns a row's options, and
> `configureMenu(for:indexPath:)` builds its long-press menu from them.
>
> ```swift theme={null}
> final class AddMembersViewController: CometChatUsers {
>     override func defaultSetup() {
>         hideSearch = true
>         super.defaultSetup()
>         selectionMode = .multiple
>         hideUserStatus = true
>     }
>
>     override func updateNavigationBarTitleWithCount(_ count: Int) {
>         navigationItem.title = count == 0 ? "Add members" : "\(count) selected"
>     }
>
>     override func tickButtonTapped() {
>         super.tickButtonTapped()
>         navigationController?.popViewController(animated: true)
>     }
> }
> ```

***

## Style

> [tab] SwiftUI
>
> ```swift theme={null}
> var style = CometChatUsersStyle()
> style.backgroundColor = Color(.systemGroupedBackground)
> style.stickyHeaderTextColor = .indigo
> style.itemStyle = UserListItemStyle(titleColor: .indigo, avatarStyle: .init(size: 48),
>                                     statusIndicatorColor: .mint)
> style.retryButtonCornerRadius = 20
>
> CometChatUsers(style: style)
> ```
>
> Unset properties fall through to the theme, so a style carries only what you change, and
> an app-wide `.cometChatTheme(_:)` reaches everything a style leaves alone.
>
> | Property | Styles |
> | - | - |
> | `backgroundColor` | the screen, the pinned headers and the presence dot's ring |
> | `navigationBarBackgroundColor`, `navigationBarItemsTintColor` | the navigation bar and its buttons |
> | `backIcon`, `backIconTint` | the back button, when shown; its tint is `navigationBarItemsTintColor` unless set |
> | `stickyHeaderTextColor`, `stickyHeaderFont`, `stickyHeaderBackgroundColor` | the letter headers — pinned, the letter alone; no fill unless `stickyHeaderBackgroundColor` is set |
> | `itemStyle.titleColor` / `titleFont` | the name |
> | `itemStyle.avatarStyle` | the avatar's size, colours and font |
> | `itemStyle.statusIndicatorColor` | the presence dot |
> | `itemStyle.checkboxSelectedColor`, `checkboxStrokeColor` | the checkbox glyphs |
> | `itemStyle.checkBox…` (stroke, corner, background, icon) | draws the checkbox from parts instead of the glyphs |
> | `itemStyle.selectedBackgroundColor` | a selected row's fill |
> | `itemStyle.separatorColor` / `separatorHeight` | the separator, shown with `hideSeparator: false` |
> | `emptyState…`, `errorState…`, `retryButton…` | the state views and Retry |
> | `loadingStateSurfaceColor` | the shimmer |
>
> > [!NOTE]
> >
> > On iOS 26 the navigation bar is Liquid Glass and the Kit leaves it to the system. Below
> > iOS 26, or with Reduce Transparency on, the bar is filled with the list's background.
> > Setting `navigationBarBackgroundColor` fills it everywhere.
>
> The title, the search field and the selection bar's items belong to the system's
> navigation bar. `titleColor`, `titleFont`, the `search…` and `toolbarSeparator…`
> properties and `popupMenuStyle` have no effect. The selection bar takes
> `discardSelectionIcon`, `submitSelectionIcon`, their tints and `selectionCountTextColor` /
> `Font`; `strokeColor`, `strokeWidth` and `cornerRadius` draw a border and rounding around
> the list. The stock row has no subtitle, so `itemStyle.subtitleColor` / `subtitleFont`
> style nothing either; a `subtitleView` styles itself.

> [tab] UIKit
>
> ```swift theme={null}
> let style = UsersStyle()
> style.headerTitleColor = .secondaryLabel
> style.listItemTitleFont = .preferredFont(forTextStyle: .headline)
> style.listItemSelectedBackground = UIColor.systemTeal.withAlphaComponent(0.15)
> style.retryButtonCornerRadius = 20
>
> let users = CometChatUsers().set(style: style)
> ```
>
> Every `UsersStyle` property is optional and resolved from the theme when the screen draws.
> Besides the row, header and search properties it has `backIcon`, `backIconTint`,
> `discardSelectionIcon`, `discardSelectionIconTint`, `submitSelectionIcon`,
> `submitSelectionIconTint`, `stickyTitleBackgroundColor`, `separatorHeight` and
> `shimmerColor`. The six `retryButton…` properties style the Retry button.
> `listItemSubTitleTextColor` and `listItemSubTitleFont` style nothing: the row has no
> subtitle of its own.
>
> `CometChatUsers.style`, `CometChatUsers.avatarStyle` and
> `CometChatUsers.statusIndicatorStyle` are the defaults every new instance copies:
>
> ```swift theme={null}
> CometChatUsers.style.headerTitleColor = .systemIndigo
> CometChatUsers.avatarStyle.cornerRadius = 8
> CometChatUsers.statusIndicatorStyle.backgroundColor = .systemMint
> ```
>
> Change a screen's `style` after it has loaded and call `refreshStyle()` — `set(style:)` does
> that for you.
>
> > [!NOTE]
> >
> > `navigationBarTintColor` fills the navigation bar. Left unset, the bar is filled with the
> > list's background — except on iOS 26, where the bar is Liquid Glass and the Kit leaves it
> > to the system.

***

## Next Steps

> [card] [Groups](https://www.cometchat.com/docs/ui-kit/ios/v6/groups.md)
>
> The groups list, built the same way

> [card] [New Chat](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-new-chat.md)
>
> Start conversations from users and groups

> [card] [Theming](https://www.cometchat.com/docs/ui-kit/ios/v6/theming.md)
>
> Colour, typography and shape tokens

> [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.