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

# Mentions Formatter

> Configure @mentions in the CometChat iOS UI Kit v6: who can be mentioned, the limit, mention-all, mention taps and mention colours.

> [accordion] AI Integration Quick Reference
>
> ```json theme={null}
> {
>   "products": ["CometChatSwiftUI", "CometChatUIKit"],
>   "class": "CometChatMentionsFormatter (CometChatCore, open, conforms to CometChatTextFormatter)",
>   "properties": ["mentionLimit", "disableMentionAll", "mentionsType", "mentionsVisibility", "onMentionClick", "onMentionAllClick"],
>   "methods": ["setMentionAllLabel(_:_:)", "setUsersRequestBuilder(_:)", "setGroupMembersRequestBuilder(_:)"],
>   "components": "CometChatMessageComposer, CometChatMessageList, CometChatConversations, CometChatThreadHeader, CometChatPinnedMessages, CometChatSavedMessages",
>   "wire format": "<@uid:UID> for a user, <@all:all> for everyone"
> }
> ```

Mentions are on by default. Typing `@` in the composer lists the people you can mention — users
in a one-to-one chat, the group's members in a group, with **@all** first in a group. A picked
mention is sent as `<@uid:UID>` and drawn as `@Name` everywhere the message appears.
`CometChatMentionsFormatter` is the formatter that does it; you configure it, or pass your own.

## Usage

### 1. Create the formatter

```swift theme={null}
let mentions = CometChatMentionsFormatter()
mentions.mentionLimit = 5             // per message; default 10
mentions.disableMentionAll = true     // no @all
mentions.mentionsType = .users        // search all users, even in a group
mentions.mentionsVisibility = .both   // .usersConversationOnly, .groupConversationOnly
```

| Property / method | Default | Effect |
| - | - | - |
| `mentionLimit` | `10` | mentions per message |
| `disableMentionAll` | `false` | hides @all |
| `mentionsType` | `.usersAndGroupMembers` | `.users` searches users even in a group |
| `mentionsVisibility` | `.both` | where mentions are offered: `.usersConversationOnly`, `.groupConversationOnly` |
| `setMentionAllLabel(_:_:)` | `all` | @all's id and label, together |
| `setUsersRequestBuilder(_:)` | the Kit's | filter which users can be mentioned |
| `setGroupMembersRequestBuilder(_:)` | the Kit's | filter which members can be mentioned |

### 2. Pass it to a component

> [tab] SwiftUI
>
> The composer's `textFormatters` replaces its list — `nil`, the default, is one mentions
> formatter. Keep yours in `@State` so it is not rebuilt on every render:
>
> ```swift TeamComposer.swift theme={null}
> import SwiftUI
> import CometChatSwiftUI
> import CometChatSDK
>
> struct TeamComposer: View {
>     let group: CometChatSDK.Group
>     @State private var mentions: CometChatMentionsFormatter = {
>         let formatter = CometChatMentionsFormatter()
>         formatter.mentionLimit = 5
>         formatter.disableMentionAll = true
>         return formatter
>     }()
>
>     var body: some View {
>         CometChatMessageComposer(group: group, textFormatters: [mentions])
>     }
> }
> ```
>
> The message list makes its own mentions formatter; configure mention-all there directly:
>
> ```swift theme={null}
> CometChatMessageList(group: guideGroup, disableMentionAll: true)
> CometChatMessageList(group: guideGroup, mentionAllLabelId: "channel", mentionAllLabel: "channel")
> ```

> [tab] UIKit
>
> The composer's mentions formatter is its first text formatter. Configure it in place:
>
> ```swift theme={null}
> let composer = CometChatMessageComposer()
> composer.set(group: guideGroup)
> if let mentions = composer.textFormatters.first as? CometChatMentionsFormatter {
>     mentions.mentionLimit = 5
>     mentions.mentionsVisibility = .groupConversationOnly
>     mentions.disableMentionAll = true
>     mentions.setMentionAllLabel("channel", "channel")
> }
> ```
>
> The message list and the conversations list take mention-all directly:
>
> ```swift theme={null}
> let list = CometChatMessageList()
> list.disableMentionAll = true
> list.setMentionAllLabel("channel", "channel")
> ```

> [!NOTE]
>
> In both toolkits a mention always starts with `@`
> (a custom tracking character is ignored), and mention-all shows as `@` and its id — `@all`.

## Mention Click Handling

A picked suggestion in the composer:

> [tab] SwiftUI
>
> ```swift theme={null}
> CometChatMessageComposer(group: guideGroup, onMentionClick: { item in
>     print("mentioned", item.name)
> })
> ```

> [tab] UIKit
>
> The UIKit composer has no pick callback. The formatter's `onMentionClick` and
> `onMentionAllClick` are stored but not called.

A tapped mention in a message bubble does nothing by default. In SwiftUI, take the tap by
registering the text bubble factory with a callback:

```swift theme={null}
CometChatMessageList(
    group: guideGroup,
    bubbleFactories: [TextBubbleFactory(onMentionClick: { user in print("open profile of", user.name) })]
)
```

The handler receives the mentioned user as a `ChatUser`. The UIKit list has no mention tap.

## Styling Mentions

### Composer mention style

> [tab] SwiftUI
>
> In the input, a mention of someone else is drawn in the theme's `primary` and a mention of you
> in `warning`. Change them through the theme — see [Theming](https://www.cometchat.com/docs/ui-kit/ios/v6/theming.md).

> [tab] UIKit
>
> ```swift theme={null}
> let style = MentionTextStyle()
> style.textColor = .systemIndigo
> style.loggedInUserTextColor = .systemOrange
> let composer = CometChatMessageComposer()
> composer.mentionStyle = style
> ```
>
> `mentionStyle` applies to mentions inserted afterwards.

### Message bubble mention style

> [tab] SwiftUI
>
> A mention of someone else uses the text bubble's `mentionColor`, with a 20 % tint behind it; a
> mention of you, and @all, stay `warning`:
>
> ```swift theme={null}
> var text = TextBubbleStyle()
> text.mentionColor = .indigo
> var bubble = MessageBubbleStyle()
> bubble.textBubbleStyle = text
> var style = CometChatMessageListStyle()
> style.incomingBubbleStyle = bubble
> _ = CometChatMessageList(style: style, user: guideUser)
> ```

> [tab] UIKit
>
> Bubble mentions follow the theme: someone else in `primary` on incoming bubbles and `white` on
> outgoing ones; you and @all in `warning`. Change `CometChatUIKitTheme.shared`'s colours to
> change them.

### Conversations mention style

The last-message line runs the formatters, so a mention reads `@Name`. Colour it:

> [tab] SwiftUI
>
> ```swift theme={null}
> var style = CometChatConversationsStyle()
> style.mentionTextColor = .indigo
> _ = CometChatConversations(style: style)
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let conversations = CometChatConversations()
> conversations.style.mentionTextColor = .systemIndigo
> ```

## Customization Matrix

| What | SwiftUI | UIKit |
| - | - | - |
| Limit, type, visibility, @all | a `CometChatMentionsFormatter` in `textFormatters:` | `composer.textFormatters.first as? CometChatMentionsFormatter` |
| @all in the list | `disableMentionAll:`, `mentionAllLabelId:` + `mentionAllLabel:` | `disableMentionAll`, `setMentionAllLabel(_:_:)` |
| Pick in the composer | `onMentionClick:` | — |
| Tap in a bubble | `TextBubbleFactory(onMentionClick:)` | — |
| Composer colours | theme `primary` / `warning` | `mentionStyle` |
| Bubble colours | `TextBubbleStyle.mentionColor` | theme |
| Conversations colour | `mentionTextColor` | `style.mentionTextColor` |
| Turn mentions off | `disableMentions: true` (removes every formatter) | — |

## Next Steps

> [card] [Text Formatter Base Class](https://www.cometchat.com/docs/ui-kit/ios/v6/custom-text-formatter-guide.md)
>
> Write your own formatter

> [card] [Message Composer](https://www.cometchat.com/docs/ui-kit/ios/v6/message-composer.md)
>
> The composer's mention options

> [card] [Message List](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md)
>
> Bubble factories and styles

> [card] [All Guides](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-overview.md)
>
> Browse the other guides


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