AI Integration Quick Reference
AI Integration Quick Reference
CometChatCore, CometChatSwiftUI
and CometChatUIKit. An app adds one toolkit; CometChatCore and the Chat SDK come with it.
Module Structure
An app adds one toolkit —
CometChatSwiftUI or CometChatUIKit. Both declare components
with the same names (CometChatConversations, CometChatMessageList …), so one Swift file
cannot import both.
The Layers
Both toolkits read the same stores, so they cannot disagree about what to show — only how
it is drawn.
Value types
Stores publish value types, not SDK objects:ConversationsState.populated(entries, hasMore:),
ChatConversation, ChatUser, ChatGroup, ChatMessage. They are Sendable, so they can
leave an SDK callback queue under Swift 6.
The store keeps the SDK objects alongside, keyed by id, so the toolkits’ callbacks hand you SDK
types — onItemClick gives you a CometChatSDK.Conversation you can pass to the rest of your
app.
State
Each store’sstate is an enum of what the screen can show. The conversations list’s:
Behaviour hooks: policies
A store takes a policy — a value of closures, swappable without subclassing:MessageListPolicy, MessageOptionsPolicy (who may edit, delete, report, message privately)
and others follow the same shape. Stores are also non-final, for anything a policy does not
cover.
Data Flow: End to End
Fetching conversations
- The component appears and asks its store to fetch.
- The store builds the SDK request (yours, if you passed a request builder) and fetches a page.
- The SDK answers on its own queue. The store maps the result to value types there, then hops to the main actor.
- The store publishes
.populated(entries, hasMore:); the toolkit renders it. - Scrolling to the end fetches the next page —
.paginating, then.populatedagain.
Real-time updates
- The store registers SDK listeners under a unique id, and removes them when it goes.
- A message, receipt, typing indicator or presence change arrives from the SDK.
- The store applies its merge rule — move the row to the top, bump the unread count, show typing — and publishes a new state.
This user’s own actions
The SDK does not tell the Kit what this user did. So the component that acts announces it onCometChatEvents, and every other store listening updates:
- The user deletes a conversation in
CometChatConversations. - The store calls the SDK; on success it removes the row and emits
conversationDeleted. - Any other store showing that conversation hears the event and updates.
Events (Cross-Component Communication)
There is one bus,CometChatEvents, with seven families: message, user, group, conversation,
call, UI and thread. SwiftUI listens with view modifiers (.onCometChatUserBlocked { … }) or
AsyncStreams (CometChatEvents.userEvents); UIKit has per-family buses and listener protocols
(CometChatUserEvents, CometChatUserEventListener), which are views of the same bus. Delivery
is on the main actor, in order.
Component-Level Overrides
Override points
1. Inject a store
- SwiftUI
- UIKit
InjectedStore.swift
2. Seed a store for previews and tests
A seeded store fetches nothing and registers no listeners:- SwiftUI
- UIKit
events: — pass CometChatEvents() for an isolated bus, so a test hears only
its own events.
Component ↔ Store Mapping
Related
Overview
Choosing a toolkit
Events
The event bus in full
Methods
CometChatSession
Upgrading from v5
What changed for v5 apps