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

# Building A One-to-One / Group Chat

> Open a single one-to-one or group chat directly — no conversation list — with the CometChat iOS UI Kit v6 SwiftUI or UIKit toolkit.

> [accordion] AI Integration Quick Reference
>
> | Field | Value |
> | - | - |
> | Components | `CometChatMessageHeader`, `CometChatMessageList`, `CometChatMessageComposer` |
> | Layout | Single chat window — no conversation list |
> | Input | an SDK `User` (one-to-one) or `Group`, fetched with `CometChat.getUser(UID:)` / `CometChat.getGroup(GUID:)` |
> | SwiftUI | `CometChatMessageList(user:group:)` filling the screen, with `CometChatMessageHeader(user:group:)` and `CometChatMessageComposer(user:group:)` as bars over it: `safeAreaBar(edge:)` on iOS 26 (the rows fade softly under them), `safeAreaInset(edge:)` before |
> | UIKit | three `UIView`s configured with `set(user:)` / `set(group:)`; the list full-bleed in a child `UIViewController` whose `additionalSafeAreaInsets` are the bars' heights, and on iOS 26 a `UIScrollEdgeElementContainerInteraction` on each bar |
> | Prerequisite | Complete [SwiftUI](https://www.cometchat.com/docs/ui-kit/ios/v6/getting-started-swiftui.md) or [UIKit](https://www.cometchat.com/docs/ui-kit/ios/v6/getting-started-uikit.md) Getting Started Steps 1–3 first |
> | Pattern | Support chat, embedded widgets, focused messaging |

This guide builds a single chat window — no conversation list. Users go straight into a one-to-one or
group chat. Good for support chat, dating apps, or a chat opened from a notification.

It assumes you have completed the Getting Started guide for your toolkit (project created, package added,
`initialize` and `login` working).

***

## What You're Building

![A single chat: messages with reactions, a quoted reply with a thread, a missed call, the New separator, an edited and a deleted message](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/docs-messageListMixed.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=d1afd10cac22a4e9d085b7e6ff226d42)

Three components: the message list fills the screen, and the header and the composer are bars over it, so
the rows scroll under their Liquid Glass on iOS 26 and fade softly behind them:

1. **Message header** — the user's or group's name, avatar, and status or member count
2. **Message list** — the chat history, live, with reactions, receipts and threads
3. **Message composer** — text input with attachments, voice notes, stickers and mentions

***

## Step 1: Set Up the Message Screen

> [tab] SwiftUI
>
> Create `MessageView.swift`. The list fills the screen, and the header and the composer are bars over it.
> The rows scroll under their Liquid Glass on iOS 26 and still come to rest clear of them. Host the bars
> with `safeAreaBar` on iOS 26: it also carries the list's scroll edge effect under each bar, so the rows
> fade softly behind it. Earlier versions have no edge effect, and `safeAreaInset` hosts the bars the same
> way. Stacked in a `VStack` instead, nothing passes under the bars and the glass has nothing to show.
>
> This chat is the whole app, so there is nowhere to go back to — hide the header's back button:
>
> ```swift MessageView.swift theme={null}
> import SwiftUI
> import CometChatSwiftUI
> import CometChatSDK
>
> struct MessageView: View {
>     let user: CometChatSDK.User?
>     let group: CometChatSDK.Group?
>
>     var body: some View {
>         CometChatMessageList(user: user, group: group)
>             .modifier(ChatBars(
>                 header: CometChatMessageHeader(user: user, group: group, hideBackIcon: true),
>                 composer: CometChatMessageComposer(user: user, group: group)))
>     }
> }
>
> /// The header and the composer as bars over the list: the rows scroll under them and rest clear of them.
> struct ChatBars<Header: View, Composer: View>: ViewModifier {
>     let header: Header
>     let composer: Composer
>
>     func body(content: Content) -> some View {
>         let list = content.frame(maxWidth: .infinity, maxHeight: .infinity)
>         if #available(iOS 26.0, *) {
>             // The list's scroll edge effect reaches under each bar: the rows fade softly behind it.
>             list
>                 .safeAreaBar(edge: .top, spacing: 0) { header }
>                 .safeAreaBar(edge: .bottom, spacing: 0) { composer }
>         } else {
>             list
>                 .safeAreaInset(edge: .top, spacing: 0) { header }
>                 .safeAreaInset(edge: .bottom, spacing: 0) { composer }
>         }
>     }
> }
> ```

> [tab] UIKit
>
> Create `MessageViewController.swift`. `CometChatMessageHeader`, `CometChatMessageList` and
> `CometChatMessageComposer` are `UIView`s: give each the chat. The list spans the screen, and the header
> and the composer sit over it, the composer on the keyboard layout guide so it rides above the keyboard.
> The rows scroll under their Liquid Glass on iOS 26. Two things make that work:
>
> * **The bars' heights are the list's safe area.** The list sits in a view controller of its own, and the
>   bars' heights reach it as that controller's `additionalSafeAreaInsets`. The list turns them into its
>   table's content inset, so the first and last rows still come to rest clear of the bars.
> * **Each bar is the table's scroll edge element (iOS 26).** A `UIScrollEdgeElementContainerInteraction`
>   on each bar carries the table's scroll edge effect under it, so the rows fade softly behind the bar.
>   Earlier versions have no edge effect and skip it.
>
> Pinned one below the other instead, nothing passes under the bars and the glass has nothing to show. The
> header's back button is hidden by default:
>
> ```swift MessageViewController.swift theme={null}
> import UIKit
> import CometChatUIKit
> import CometChatSDK
>
> final class MessageViewController: UIViewController {
>     private let user: CometChatSDK.User?
>     private let group: CometChatSDK.Group?
>     private let header = CometChatMessageHeader()
>     private let composer = CometChatMessageComposer()
>     /// Holds the list, so the bars' heights can reach it as safe area.
>     private let listController = MessageListController()
>     private var messageList: CometChatMessageList { listController.messageList }
>
>     init(user: CometChatSDK.User?, group: CometChatSDK.Group?) {
>         self.user = user
>         self.group = group
>         super.init(nibName: nil, bundle: nil)
>     }
>
>     required init?(coder: NSCoder) { fatalError("init(coder:) is not supported") }
>
>     override func viewDidLoad() {
>         super.viewDidLoad()
>         view.backgroundColor = .systemBackground
>
>         if let user {
>             header.set(user: user)
>             messageList.set(user: user)
>             composer.set(user: user)
>         } else if let group {
>             header.set(group: group)
>             messageList.set(group: group)
>             composer.set(group: group)
>         }
>
>         // The list first, so the bars sit over it.
>         addChild(listController)
>         for part in [listController.view, header, composer] as [UIView] {
>             part.translatesAutoresizingMaskIntoConstraints = false
>             view.addSubview(part)
>         }
>         listController.didMove(toParent: self)
>         NSLayoutConstraint.activate([
>             listController.view.topAnchor.constraint(equalTo: view.topAnchor),
>             listController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
>             listController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
>             // To the composer's bottom: the rows pass under the composer, never under the keyboard.
>             listController.view.bottomAnchor.constraint(equalTo: composer.bottomAnchor),
>
>             header.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
>             header.leadingAnchor.constraint(equalTo: view.leadingAnchor),
>             header.trailingAnchor.constraint(equalTo: view.trailingAnchor),
>
>             composer.leadingAnchor.constraint(equalTo: view.leadingAnchor),
>             composer.trailingAnchor.constraint(equalTo: view.trailingAnchor),
>             composer.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor),
>         ])
>
>         if #available(iOS 26.0, *) {
>             // The table's scroll edge effect reaches under each bar: the rows fade softly behind it.
>             for (bar, edge) in [(header as UIView, UIRectEdge.top), (composer, .bottom)] {
>                 let element = UIScrollEdgeElementContainerInteraction()
>                 element.scrollView = messageList.tableView
>                 element.edge = edge
>                 bar.addInteraction(element)
>             }
>         }
>     }
>
>     // The bars' heights, as the list's safe area. The composer's grows with the keyboard and a reply
>     // preview, and the list keeps its newest row clear of it.
>     override func viewDidLayoutSubviews() {
>         super.viewDidLayoutSubviews()
>         let container: UIView = listController.view
>         // The list's safe area is the screen's (the status bar, the home indicator) plus `added`.
>         let added = listController.additionalSafeAreaInsets
>         let inherited = container.safeAreaInsets
>         let headerBottom = view.convert(header.frame, to: container).maxY
>         let composerTop = view.convert(composer.frame, to: container).minY
>         let insets = UIEdgeInsets(
>             top: max(0, headerBottom - (inherited.top - added.top)),
>             left: 0,
>             bottom: max(0, container.bounds.maxY - composerTop - (inherited.bottom - added.bottom)),
>             right: 0)
>         if insets != added { listController.additionalSafeAreaInsets = insets }
>     }
> }
>
> /// The list, full-bleed, in a view controller of its own: its `additionalSafeAreaInsets` are how the
> /// bars' heights reach the list.
> final class MessageListController: UIViewController {
>     let messageList = CometChatMessageList()
>
>     override func viewDidLoad() {
>         super.viewDidLoad()
>         messageList.translatesAutoresizingMaskIntoConstraints = false
>         view.addSubview(messageList)
>         NSLayoutConstraint.activate([
>             messageList.topAnchor.constraint(equalTo: view.topAnchor),
>             messageList.leadingAnchor.constraint(equalTo: view.leadingAnchor),
>             messageList.trailingAnchor.constraint(equalTo: view.trailingAnchor),
>             messageList.bottomAnchor.constraint(equalTo: view.bottomAnchor),
>         ])
>     }
> }
> ```

***

## Step 2: Fetch the User or Group

The message components take the SDK's `User` or `Group`, so fetch the one you want to chat with. The
Chat SDK's `getUser` and `getGroup` call back on the SDK's own queue, so wrap them in a type that is not
on the main actor — a closure created on the main actor and called from another queue traps under Swift
6's isolation checks. The same helper serves both toolkits:

```swift ChatLookup.swift theme={null}
import CometChatSDK
import CometChatCore

/// Fetches who to chat with. Deliberately not `@MainActor`: the SDK answers on its own queue.
enum ChatLookup {
    static func user(uid: String) async throws -> CometChatSDK.User {
        let box: SDKBox<CometChatSDK.User> = try await withCheckedThrowingContinuation { continuation in
            CometChat.getUser(UID: uid, onSuccess: { user in
                if let user {
                    continuation.resume(returning: SDKBox(user))
                } else {
                    continuation.resume(throwing: CometChatError.unknown)
                }
            }, onError: { error in
                continuation.resume(throwing: CometChatError(code: error?.errorCode ?? "ERR_UNKNOWN",
                                                             message: error?.errorDescription ?? ""))
            })
        }
        return box.value
    }

    static func group(guid: String) async throws -> CometChatSDK.Group {
        let box: SDKBox<CometChatSDK.Group> = try await withCheckedThrowingContinuation { continuation in
            CometChat.getGroup(GUID: guid, onSuccess: { group in
                continuation.resume(returning: SDKBox(group))
            }, onError: { error in
                continuation.resume(throwing: CometChatError(code: error?.errorCode ?? "ERR_UNKNOWN",
                                                             message: error?.errorDescription ?? ""))
            })
        }
        return box.value
    }
}
```

`SDKBox` (from `CometChatCore`) carries the SDK object across the queue hop.

***

## Step 3: Launch a One-to-One Chat

After `login`, fetch the other user and show the chat. Replace `cometchat-uid-2` with the UID of the user
to chat with.

> [tab] SwiftUI
>
> ```swift ContentView.swift theme={null}
> import SwiftUI
> import CometChatSwiftUI
> import CometChatSDK
>
> struct ContentView: View {
>     @State private var user: CometChatSDK.User?
>     @State private var errorText: String?
>
>     var body: some View {
>         Group {
>             if let user {
>                 MessageView(user: user, group: nil)
>             } else if let errorText {
>                 Text(errorText)
>             } else {
>                 ProgressView()
>             }
>         }
>         .task {
>             do {
>                 try await CometChatSession.initialize(appID: "APP_ID", region: "REGION")
>                 if CometChatSession.loggedInUser == nil {
>                     _ = try await CometChatSession.login(uid: "UID", authKey: "AUTH_KEY")
>                 }
>                 user = try await ChatLookup.user(uid: "cometchat-uid-2")
>             } catch {
>                 errorText = error.localizedDescription
>             }
>         }
>     }
> }
> ```

> [tab] UIKit
>
> ```swift SceneDelegate.swift theme={null}
> import UIKit
> import CometChatUIKit
>
> final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
>     var window: UIWindow?
>
>     func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
>                options connectionOptions: UIScene.ConnectionOptions) {
>         guard let windowScene = scene as? UIWindowScene else { return }
>         let window = UIWindow(windowScene: windowScene)
>         window.rootViewController = UIViewController()
>         window.makeKeyAndVisible()
>         self.window = window
>
>         Task {
>             do {
>                 try await CometChatSession.initialize(appID: "APP_ID", region: "REGION")
>                 if CometChatSession.loggedInUser == nil {
>                     _ = try await CometChatSession.login(uid: "UID", authKey: "AUTH_KEY")
>                 }
>                 let user = try await ChatLookup.user(uid: "cometchat-uid-2")
>                 window.rootViewController = MessageViewController(user: user, group: nil)
>             } catch {
>                 print("Could not open the chat:", error)
>             }
>         }
>     }
> }
> ```

***

## Step 4: Launch a Group Chat

For a group, fetch the group instead and pass it as `group`. Every new app has a test group,
`cometchat-guid-1`; the logged-in user must be a member to see its messages.

> [tab] SwiftUI
>
> ```swift theme={null}
> let group = try await ChatLookup.group(guid: "cometchat-guid-1")
> _ = MessageView(user: nil, group: group)
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let group = try await ChatLookup.group(guid: "cometchat-guid-1")
> let chat = MessageViewController(user: nil, group: group)
> ```

In the full screen, hold the group in `@State` (SwiftUI) or set the controller as the window's root
(UIKit) exactly as Step 3 does with the user.

***

## Step 5: Run the Project

Build and run. The chat opens straight after login, with the header, the history and the composer. The
composer needs the camera, microphone and photo-library usage descriptions in `Info.plist` — see Step 3
of [Getting Started](https://www.cometchat.com/docs/ui-kit/ios/v6/getting-started.md).

***

## Next Steps

> [card] [Components Overview](https://www.cometchat.com/docs/ui-kit/ios/v6/components-overview.md)
>
> Explore all available UI Kit components and their customization options

> [card] [Theming](https://www.cometchat.com/docs/ui-kit/ios/v6/theming.md)
>
> Customize colors, fonts, and styles to match your brand

> [card] [Integration](https://www.cometchat.com/docs/ui-kit/ios/v6/getting-started.md)
>
> Back to the main integration guide

> [card] [Feature Guides](https://www.cometchat.com/docs/ui-kit/ios/v6/guide-overview.md)
>
> Add capabilities like threaded messages, blocking, and group management


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