Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cometchat avatar

Cometchat Ios Core

  • 7 installs
  • 70 repo stars
  • Updated June 23, 2026
  • cometchat/cometchat-skills

Foundational rules for CometChat iOS UI Kit v5 covering installation, initialization, login, and the manager pattern in Swift.

About

Teaches how CometChat works on iOS: dependency setup, initialization, login, the manager pattern, and anti-patterns. A developer reads it first before any iOS placement or component skill.

  • Confirms or creates a CocoaPods/SPM dependency manifest first
  • Covers init, login, and the manager pattern for iOS 13+

Cometchat Ios Core by the numbers

  • 7 all-time installs (skills.sh)
  • Ranked #801 of 1,039 Mobile Development skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/cometchat/cometchat-skills --skill cometchat-ios-core

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs7
repo stars70
Last updatedJune 23, 2026
Repositorycometchat/cometchat-skills

What it does

Foundational rules for CometChat iOS UI Kit v5 covering installation, initialization, login, and the manager pattern in Swift.

Files

SKILL.mdMarkdownGitHub ↗

Purpose

This is the foundational skill for every CometChat iOS UI Kit v5 integration. It teaches HOW CometChat works on iOS — initialization, login, the manager pattern, and anti-patterns — so you can write project-appropriate code instead of relying on templates.

Read this skill first, before any placement or component skill.

---

1. Installation

0. First — confirm a dependency manifest exists (or create one)

A freshly-created Xcode project (File → New → App from the GUI) ships *no `Podfile`, no `Package.swift`, and no Swift Package Manager refs in `.xcodeproj/project.pbxproj**. Before touching any of the integration code below, you MUST establish a dependency-management mechanism — otherwise import CometChatUIKitSwift will hit Unable to resolve module dependency: 'CometChatSDK'` at the first build attempt and the entire integration is dead on arrival.

Detection:

ls Podfile Package.swift 2>/dev/null
grep -l "XCRemoteSwiftPackageReference\|repositoryURL.*cometchat" *.xcodeproj/project.pbxproj 2>/dev/null

If all three return empty → fresh Xcode project, no dep manager. Pick one and set it up before continuing:

Option A — CocoaPods (most common, easiest to script):

cd <project-root>
cat > Podfile <<'POD'
platform :ios, '13.0'
use_frameworks!

target 'YourAppTargetName' do
  pod 'CometChatUIKitSwift', '~> 5.1'
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_USER_SCRIPT_SANDBOXING'] = 'NO'
    end
  end
end
POD
pod install

After pod install, work from YourApp.xcworkspace (NOT .xcodeproj) — CocoaPods rewires the workspace to include the Pods project.

Option B — Swift Package Manager (no Podfile, no `.xcworkspace`):

The user must add the package via Xcode's GUI (the SPM dependency lives in *.xcodeproj/project.pbxproj and there's no clean CLI tooling to edit that file safely). Print these instructions verbatim:

1. Open <YourApp>.xcodeproj in Xcode
2. File → Add Package Dependencies…
3. Paste URL: https://github.com/cometchat/cometchat-uikit-ios
4. Add Package → keep "Up to Next Major Version" defaults → Add Package again
5. Confirm CometChatUIKitSwift appears under your app target's Frameworks, Libraries, and Embedded Content

Then verify the package landed:

grep -E "cometchat-uikit-ios|CometChatUIKitSwift" *.xcodeproj/project.pbxproj | head -2

If grep returns matches, the SPM dep is in. If it doesn't, the user didn't complete step 4 in Xcode — surface that explicitly and stop until they have.

HARD STOP if neither option is in place. Do not write import CometChatUIKitSwift into any Swift file until either pod install completes successfully or the SPM grep above returns matches. Skipping this step produces an integration that compiles only after the user does extra setup work — a worse outcome than asking them up-front.

CocoaPods (full reference — only if you skipped Option A above)

Add to your Podfile:

platform :ios, '13.0'
use_frameworks!

target 'YourApp' do
  pod 'CometChatUIKitSwift', '~> 5.1'
end

Then run:

pod install

Important: Disable User Script Sandboxing (Xcode 15+)

After running pod install, you must disable user script sandboxing in your project's Build Settings:

1. Open your .xcworkspace file 2. Select your app target 3. Go to Build Settings 4. Search for "User Script Sandboxing" 5. Set ENABLE_USER_SCRIPT_SANDBOXING to No

Or add this to your Podfile to do it automatically:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_USER_SCRIPT_SANDBOXING'] = 'NO'
    end
  end
end

Swift Package Manager

Add the package URL in Xcode (File → Add Package Dependencies):

CometChat UI Kit (includes SDK):

https://github.com/cometchat/cometchat-uikit-ios

CometChat SDK only (if needed separately):

https://github.com/cometchat/chat-sdk-ios

CometChat Calls SDK (for voice/video calls):

https://github.com/cometchat/cometchat-calls-sdk-ios

Or add to Package.swift:

dependencies: [
    .package(url: "https://github.com/cometchat/cometchat-uikit-ios", from: "5.0.0"),
    // Optional: Add calls SDK for voice/video
    // .package(url: "https://github.com/cometchat/cometchat-calls-sdk-ios", from: "4.0.0")
]

GitHub Repositories

PackageRepositoryDescription
UI Kithttps://github.com/cometchat/cometchat-uikit-iosReady-to-use UI components
Chat SDKhttps://github.com/cometchat/chat-sdk-iosCore messaging SDK
Calls SDKhttps://github.com/cometchat/cometchat-calls-sdk-iosVoice & video calling
Sample Apphttps://github.com/cometchat/cometchat-sample-app-iosSample implementation

---

2. Initialization

CometChat must be initialized exactly once before any UI component is used. Initialization is asynchronous and must complete fully before mounting any CometChat* view controller.

UIKitSettings Builder

import CometChatUIKitSwift

let uiKitSettings = UIKitSettings()
    .set(appID: "YOUR_APP_ID")
    .set(authKey: "YOUR_AUTH_KEY")  // Required for dev mode
    .set(region: "us")               // "us", "eu", or "in"
    .subscribePresenceForAllUsers()  // Enable online/offline indicators
    .build()

Init must happen once

Use a singleton manager to prevent double-init:

import CometChatUIKitSwift
import CometChatSDK

final class CometChatManager {
    static let shared = CometChatManager()
    
    private var isInitialized = false
    private var initializationError: Error?
    
    private init() {}
    
    func initialize(
        appID: String,
        authKey: String,
        region: String,
        completion: @escaping (Result<Bool, Error>) -> Void
    ) {
        guard !isInitialized else {
            completion(.success(true))
            return
        }
        
        let uiKitSettings = UIKitSettings()
            .set(appID: appID)
            .set(authKey: authKey)
            .set(region: region)
            .subscribePresenceForAllUsers()
            .build()
        
        CometChatUIKit(uiKitSettings: uiKitSettings) { result in
            switch result {
            case .success(let success):
                self.isInitialized = success
                completion(.success(success))
            case .failure(let error):
                self.initializationError = error
                completion(.failure(error))
            }
        }
    }
}

Init in AppDelegate (UIKit apps)

import UIKit
import CometChatUIKitSwift

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        
        CometChatManager.shared.initialize(
            appID: "YOUR_APP_ID",
            authKey: "YOUR_AUTH_KEY",
            region: "us"
        ) { result in
            switch result {
            case .success:
                print("CometChat initialized successfully")
            case .failure(let error):
                print("CometChat initialization failed: \(error)")
            }
        }
        
        return true
    }
}

Init in App struct (SwiftUI apps)

import SwiftUI
import CometChatUIKitSwift

@main
struct YourApp: App {
    
    init() {
        CometChatManager.shared.initialize(
            appID: "YOUR_APP_ID",
            authKey: "YOUR_AUTH_KEY",
            region: "us"
        ) { result in
            switch result {
            case .success:
                print("CometChat initialized successfully")
            case .failure(let error):
                print("CometChat initialization failed: \(error)")
            }
        }
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

---

3. Login

Development mode

Use CometChatUIKit.login(uid:) with a test UID. Every new CometChat app comes with five pre-created test users: cometchat-uid-1 through cometchat-uid-5.

Important: The login callback uses .success and .onError cases, NOT Swift's standard Result type.

CometChatUIKit.login(uid: "cometchat-uid-1") { result in
    switch result {
    case .success(let user):
        print("Logged in as: \(user.name ?? "")")
        // Proceed to chat UI
    case .onError(let error):
        print("Login failed: \(error.errorDescription)")
    @unknown default:
        break
    }
}

Production mode

Use CometChatUIKit.login(authToken:) with a token obtained from your backend:

CometChatUIKit.login(authToken: authToken) { result in
    switch result {
    case .success(let user):
        print("Logged in as: \(user.name ?? "")")
    case .onError(let error):
        print("Login failed: \(error.errorDescription)")
    @unknown default:
        break
    }
}

Getting the current logged-in user

// Synchronous — use when you know init is complete
if let currentUser = CometChatUIKit.getLoggedInUser() {
    print("Logged in as: \(currentUser.name ?? "")")
}

Logout

if let currentUser = CometChat.getLoggedInUser() {
    CometChatUIKit.logout(user: currentUser) { result in
        switch result {
        case .success:
            print("Logged out successfully")
        case .onError(let error):
            print("Logout failed: \(error.errorDescription)")
        @unknown default:
            break
        }
    }
}

---

3.1 Error Handling

CometChat uses CometChatException for errors. Important: Use errorDescription property, NOT localizedDescription.

CometChatException Properties

// CometChatException has these properties:
error.errorCode        // String - error code like "ERR_UID_NOT_FOUND"
error.errorDescription // String - human-readable description
error.details          // [String: Any]? - additional details

Correct Error Handling

CometChatUIKit.login(uid: "user-123") { result in
    switch result {
    case .success(let user):
        print("Logged in: \(user.name ?? "")")
    case .onError(let error):
        print("Error: \(error.errorDescription)")
        print("Code: \(error.errorCode)")
    }
}

Error Handling in Closures

// For onError closures where error might be optional:
CometChat.getUser(UID: "user-123") { user in
    print("User: \(user?.name ?? "")")
} onError: { error in
    // error is CometChatException? (optional)
    print("Error: \(error?.errorDescription ?? "Unknown error")")
}

// For ApiStatus enum results:
CometChatUIKit.create(user: newUser) { result in
    switch result {
    case .success(let user):
        print("Created: \(user.name ?? "")")
    case .onError(let error):
        // error is CometChatException (non-optional)
        print("Error: \(error.errorDescription)")
    }
}

Common Error Codes

CodeDescription
ERR_UID_NOT_FOUNDUser doesn't exist
ERR_ALREADY_LOGGED_INUser already logged in
ERR_NOT_LOGGED_INNo active session
AUTH_ERR_AUTH_TOKEN_NOT_FOUNDInvalid auth token
ERR_INVALID_APP_IDWrong App ID
ERR_INVALID_API_KEYWrong API/Auth Key

---

4. Credentials Management

Using a Constants file (Development)

// Constants.swift
struct CometChatConstants {
    static let appID = "YOUR_APP_ID"
    static let authKey = "YOUR_AUTH_KEY"
    static let region = "us"
}

Important: Add Constants.swift to .gitignore for production apps.

Using Info.plist

Add keys to your Info.plist:

<key>CometChatAppID</key>
<string>YOUR_APP_ID</string>
<key>CometChatAuthKey</key>
<string>YOUR_AUTH_KEY</string>
<key>CometChatRegion</key>
<string>us</string>

Read them in code:

guard let appID = Bundle.main.object(forInfoDictionaryKey: "CometChatAppID") as? String,
      let authKey = Bundle.main.object(forInfoDictionaryKey: "CometChatAuthKey") as? String,
      let region = Bundle.main.object(forInfoDictionaryKey: "CometChatRegion") as? String else {
    fatalError("CometChat credentials not found in Info.plist")
}

Using xcconfig files (Recommended for production)

Create Debug.xcconfig and Release.xcconfig:

// Debug.xcconfig
COMETCHAT_APP_ID = your_app_id
COMETCHAT_AUTH_KEY = your_auth_key
COMETCHAT_REGION = us

Reference in Info.plist:

<key>CometChatAppID</key>
<string>$(COMETCHAT_APP_ID)</string>

---

5. The Manager Pattern

The recommended pattern for iOS is a singleton manager that handles initialization, login state, and provides a clean API for the rest of the app.

Complete CometChatManager

Important: CometChatException does NOT conform to Swift's Error protocol. Use CometChatException directly in your callbacks, not Result<T, Error>.

import Foundation
import CometChatUIKitSwift
import CometChatSDK

final class CometChatManager {
    
    // MARK: - Singleton
    static let shared = CometChatManager()
    
    // MARK: - State
    private(set) var isInitialized = false
    private(set) var currentUser: User?
    
    // MARK: - Callbacks
    var onLoginStateChanged: ((User?) -> Void)?
    
    private init() {}
    
    // MARK: - Initialization
    func initialize(
        appID: String,
        authKey: String,
        region: String,
        completion: @escaping (Bool, CometChatException?) -> Void
    ) {
        guard !isInitialized else {
            completion(true, nil)
            return
        }
        
        let uiKitSettings = UIKitSettings()
            .set(appID: appID)
            .set(authKey: authKey)
            .set(region: region)
            .subscribePresenceForAllUsers()
            .build()
        
        CometChatUIKit.init(uiKitSettings: uiKitSettings) { [weak self] result in
            DispatchQueue.main.async {
                switch result {
                case .success(let success):
                    self?.isInitialized = success
                    self?.currentUser = CometChatUIKit.getLoggedInUser()
                    completion(success, nil)
                case .failure(let error):
                    completion(false, error as? CometChatException)
                }
            }
        }
    }
    
    // MARK: - Login with UID (Development)
    func login(uid: String, completion: @escaping (User?, CometChatException?) -> Void) {
        guard isInitialized else {
            print("CometChat not initialized")
            completion(nil, nil)
            return
        }
        
        if let user = currentUser {
            completion(user, nil)
            return
        }
        
        CometChatUIKit.login(uid: uid) { [weak self] result in
            DispatchQueue.main.async {
                switch result {
                case .success(let user):
                    self?.currentUser = user
                    self?.onLoginStateChanged?(user)
                    completion(user, nil)
                case .onError(let error):
                    completion(nil, error)
                @unknown default:
                    completion(nil, nil)
                }
            }
        }
    }
    
    // MARK: - Login with Auth Token (Production)
    func loginWithToken(_ authToken: String, completion: @escaping (User?, CometChatException?) -> Void) {
        guard isInitialized else {
            print("CometChat not initialized")
            completion(nil, nil)
            return
        }
        
        CometChatUIKit.login(authToken: authToken) { [weak self] result in
            DispatchQueue.main.async {
                switch result {
                case .success(let user):
                    self?.currentUser = user
                    self?.onLoginStateChanged?(user)
                    completion(user, nil)
                case .onError(let error):
                    completion(nil, error)
                @unknown default:
                    completion(nil, nil)
                }
            }
        }
    }
    
    // MARK: - Logout
    func logout(completion: @escaping (Bool, CometChatException?) -> Void) {
        guard let user = currentUser else {
            completion(true, nil)
            return
        }
        
        CometChatUIKit.logout(user: user) { [weak self] result in
            DispatchQueue.main.async {
                switch result {
                case .success:
                    self?.currentUser = nil
                    self?.onLoginStateChanged?(nil)
                    completion(true, nil)
                case .onError(let error):
                    completion(false, error)
                @unknown default:
                    completion(false, nil)
                }
            }
        }
    }
}

Usage Example

// Initialize
CometChatManager.shared.initialize(
    appID: "YOUR_APP_ID",
    authKey: "YOUR_AUTH_KEY",
    region: "us"
) { success, error in
    if success {
        print("Initialized successfully")
    } else if let error = error {
        print("Init failed: \(error.errorDescription)")
    }
}

// Login
CometChatManager.shared.login(uid: "cometchat-uid-1") { user, error in
    if let user = user {
        print("Logged in as: \(user.name ?? "")")
        // Show chat UI
    } else if let error = error {
        print("Login failed: \(error.errorDescription)")
    }
}

// Logout
CometChatManager.shared.logout { success, error in
    if success {
        print("Logged out")
    } else if let error = error {
        print("Logout failed: \(error.errorDescription)")
    }
}

---

6. Theming

Global Theme Configuration

CometChat iOS UI Kit uses CometChatTheme for styling. Configure it before showing any UI:

// Set primary color
CometChatTheme.primaryColor = UIColor.systemBlue

// Set background colors
CometChatTheme.backgroundColor01 = UIColor.systemBackground
CometChatTheme.backgroundColor02 = UIColor.secondarySystemBackground

// Set text colors
CometChatTheme.textColorPrimary = UIColor.label
CometChatTheme.textColorSecondary = UIColor.secondaryLabel

Component-Level Styling

Each component has a static style property:

// Conversations list style
CometChatConversations.style.backgroundColor = .systemBackground
CometChatConversations.style.titleColor = .label

// Message list style
CometChatMessageList.style.backgroundColor = .systemBackground

// Avatar style — cornerRadius is a CGFloat on a CometChatCornerStyle,
// NOT a `.circle` enum case. Use a value larger than half the avatar
// dimension for a circular look.
CometChatAvatar.style.backgroundColor = .systemGray5
CometChatAvatar.style.cornerRadius = CometChatCornerStyle(cornerRadius: 100)

Dark Mode Support

CometChat automatically supports dark mode when using system colors:

CometChatTheme.primaryColor = UIColor { traitCollection in
    traitCollection.userInterfaceStyle == .dark 
        ? UIColor.systemBlue 
        : UIColor.blue
}

---

7. Localization

CometChat iOS UI Kit supports 20+ languages out of the box. The language is automatically detected from the device settings.

Supported Languages

Arabic, Chinese (Simplified), Chinese (Traditional), Dutch, English, French, German, Hindi, Hungarian, Japanese, Korean, Lithuanian, Malay, Portuguese, Russian, Spanish, Swedish, Turkish

Setting locale

CometChatLocalize is a Bundle subclass that swaps the kit's .lproj lookup at runtime. The public API is locale-only:

CometChatLocalize.set(locale: .english)        // enum value
CometChatLocalize.set(locale: "fr")            // raw string

There is no CometChatLocalize.set(key:value:) for ad-hoc key overrides — to customize specific strings, override them in your app's Localizable.strings file (the kit reads through the standard bundle lookup chain).

---

8. Anti-patterns

These are specific things NOT to do. Each one causes real bugs.

1. Do NOT call `CometChatUIKit.init()` multiple times. Init should happen once in AppDelegate or App init. Multiple init calls cause undefined behavior.

2. Do NOT show CometChat UI before init completes. Components assume the SDK is initialized. Showing UI before init finishes causes crashes.

3. Do NOT hardcode Auth Key in production code. The auth key is a secret. Use environment variables or xcconfig files. Use auth tokens in production.

4. Do NOT ignore the completion handler. Init and login are async. Always handle the completion to know when it's safe to proceed.

5. Do NOT create multiple instances of CometChatManager. Use the singleton pattern. Multiple managers cause state inconsistencies.

6. Do NOT call login while another login is in progress. Check currentUser first. Concurrent login calls cause errors.

7. Do NOT forget to handle logout. When your app's user logs out, call CometChatManager.shared.logout() to clear the CometChat session.

8. Do NOT ignore memory management. CometChat view controllers should be properly deallocated. Avoid retain cycles with closures.

9. Do NOT block the main thread. All CometChat callbacks are on the main thread. Don't do heavy work in callbacks.

10. Do NOT invent component names. CometChat exports specific components with specific names. Check the cometchat-ios-components skill before writing any code.

---

9. SDK Types Reference

Common types from CometChatSDK:

import CometChatSDK

// User — represents a chat user
let user: User

// Group — represents a chat group
let group: Group

// Conversation — wraps User or Group
let conversation: Conversation

// BaseMessage — base class for all messages
let message: BaseMessage

// TextMessage — a text message
let textMessage: TextMessage

// MediaMessage — image, video, audio, file
let mediaMessage: MediaMessage

// CustomMessage — custom data message
let customMessage: CustomMessage

Getting entities

// Get a user by UID
CometChat.getUser(UID: "user-uid") { user in
    print("User: \(user?.name ?? "")")
} onError: { error in
    print("Error: \(error?.errorDescription ?? "")")
}

// Get a group by GUID
CometChat.getGroup(GUID: "group-guid") { group in
    print("Group: \(group?.name ?? "")")
} onError: { error in
    print("Error: \(error?.errorDescription ?? "")")
}

---

10. Package Dependencies

Every CometChat iOS integration requires:

# Podfile
pod 'CometChatUIKitSwift', '~> 5.1'

This automatically includes:

  • CometChatSDK — Core SDK with types and methods
  • UI components and views
  • Localization resources
  • Asset bundles

Optional: Calling SDK

For voice/video calls, add:

pod 'CometChatCallsSDK', '~> 4.0'

The UI Kit automatically detects and enables calling features when the Calls SDK is present.

Visual Builder integration

When the dispatcher's Step 3.1 sets customize=visual and the platform resolves to ios, skills runs `cometchat builder export --platform ios` — a single CLI command that downloads the canonical static template ZIP from preview.cometchat.com/downloads/cometchat-builder-ios.zip, fetches the per-builder settings JSON, applies F3 + F10 missing-field defaults, and writes 3 files to --output (default: CometChat/):

  • MessagesVC.swift — verbatim view controller composing header + list + composer
  • ThreadedMessagesVC.swift — verbatim helper VC (imported by MessagesVC)
  • cometchat-builder-settings.jsonenvelope-shape JSON { builderId, name, settings: {...} } (no sentinel — JSON forbids // comments)

1. Run cometchat builder export

cometchat builder export --platform ios --json

Defaults to --output CometChat/. Adjust the output if the customer's project uses a different chat-surface group name (e.g. --output Chat/ for projects that use a Chat group).

CometChatBuilderSettings.loadFromJSON() looks for the envelope shape — handing it the raw settings blob causes CometChatBuilderSettings.shared to fall back to defaults silently (no error logged). The CLI always writes the envelope, so this trap is closed.

Resync = re-run the same command with --force. See cometchat-core §11.6 for the resync contract.

2. Files skills writes (after builder export)

PathContent
CometChat/CometChatApp.swiftSwiftUI wrapper that mounts CometChatConversations + pushes MessagesVC on tap. Feature flags read from CometChatBuilderSettings.shared. Skills emits this — not from the ZIP.

Files patched

PathPatch
PodfileAdd pod 'CometChatBuilder' (the canonical pod surfacing CometChatBuilderSettings.shared + loadFromJSON()). Add pod 'CometChatUIKitSwift', '~> 5.1' if not already declared. SPM equivalent: add https://github.com/cometchat/cometchat-builder-ios
AppDelegate.swift (UIKit) / App.swift (SwiftUI)Add CometChatBuilderSettings.loadFromJSON() + theme application + CometChatUIKit.init(uiKitSettings:) in application(_:didFinishLaunchingWithOptions:) — see init code below
App targetToggle cometchat-builder-settings.json for target membership in Xcode (else loadFromJSON() silently returns defaults)
Entry view — ContentView.swift (SwiftUI) or root UIViewController (UIKit)Mount CometChatApp() per Step 3c placement (modal sheet, push-navigation destination, tab item, or embedded view)
Info.plistNSMicrophoneUsageDescription + NSCameraUsageDescription if CometChatBuilderSettings.shared.callFeatures has any enabled feature

Init code — AppDelegate

// AppDelegate.swift — inside application(_:didFinishLaunchingWithOptions:)
import CometChatBuilder
import CometChatUIKitSwift

// 1. Load builder settings from bundled JSON
CometChatBuilderSettings.loadFromJSON()

// 2. Apply builder theme tokens to the kit's global theme
CometChatTheme.primaryColor = UIColor.dynamicColor(
    lightModeColor: UIColor(hex: CometChatBuilderSettings.shared.style.color.brandColor),
    darkModeColor: UIColor(hex: CometChatBuilderSettings.shared.style.color.brandColor)
)
CometChatTheme.textColorPrimary = UIColor.dynamicColor(
    lightModeColor: UIColor(hex: CometChatBuilderSettings.shared.style.color.primaryTextLight),
    darkModeColor: UIColor(hex: CometChatBuilderSettings.shared.style.color.primaryTextDark)
)
CometChatTheme.textColorSecondary = UIColor.dynamicColor(
    lightModeColor: UIColor(hex: CometChatBuilderSettings.shared.style.color.secondaryTextLight),
    darkModeColor: UIColor(hex: CometChatBuilderSettings.shared.style.color.secondaryTextDark)
)
CometChatTypography.customFontFamilyName = CometChatBuilderSettings.shared.style.typography.font

// 3. Standard UI Kit init (this file's §2 — credentials from Secrets.swift)
CometChatManager.shared.initialize(
    appID: Secrets.appID, authKey: Secrets.authKey, region: Secrets.region
) { _, _ in }

loadFromJSON() reads cometchat-builder-settings.json from the main bundle. If the file isn't a target member (Xcode → file inspector → Target Membership), CometChatBuilderSettings.shared silently falls back to defaults — this is the #1 integration bug. Sanity-check by printing CometChatBuilderSettings.shared.style.color.brandColor after loadFromJSON().

The wrapper template

// CometChat/CometChatApp.swift
import SwiftUI
import UIKit
import CometChatBuilder
import CometChatUIKitSwift
import CometChatSDK

/// Top-level chat surface emitted by the Visual Builder Visually path.
/// Master/detail SwiftUI host: `CometChatConversations` at root, `MessagesVC` pushed on tap.
/// Feature visibility flags are read from `CometChatBuilderSettings.shared`.
public struct CometChatApp: View {
    public init() {}
    public var body: some View {
        ConversationsContainer().ignoresSafeArea()
    }
}

private struct ConversationsContainer: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UINavigationController {
        let conversationsVC = CometChatConversations()
        let core = CometChatBuilderSettings.shared.chatFeatures.coreMessagingExperience
        conversationsVC.hideUserStatus = !core.userAndFriendsPresence
        conversationsVC.hideReceipts = !core.messageDeliveryAndReadReceipts

        let nav = UINavigationController(rootViewController: conversationsVC)
        conversationsVC.set(onItemClick: { [weak nav] conversation, _ in
            let vc = MessagesVC()
            if let user = conversation.conversationWith as? User { vc.user = user }
            else if let group = conversation.conversationWith as? Group { vc.group = group }
            nav?.pushViewController(vc, animated: true)
        })
        return nav
    }
    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
}

private extension UIColor {
    convenience init?(hex: String) {
        let s = hex.replacingOccurrences(of: "#", with: "")
        guard s.count == 6, let rgb = UInt32(s, radix: 16) else { return nil }
        self.init(red: CGFloat((rgb >> 16) & 0xFF) / 255,
                  green: CGFloat((rgb >> 8) & 0xFF) / 255,
                  blue: CGFloat(rgb & 0xFF) / 255,
                  alpha: 1)
    }
    static func dynamicColor(lightModeColor: UIColor?, darkModeColor: UIColor?) -> UIColor {
        UIColor { traits in
            (traits.userInterfaceStyle == .dark ? darkModeColor : lightModeColor) ?? UIColor.label
        }
    }
}

MessagesVC.swift is copied verbatim from CometChatBuilderSwift/BuilderApp/View Controllers/CometChat Components/MessagesVC.swift (inside the Ios Visual Builder ZIP at https://preview.cometchat.com/downloads/cometchat-builder-ios.zip). It composes header + list + composer in a UIViewController and wires reaction / thread / typing per CometChatBuilderSettings.shared.chatFeatures.*. Do not hand-roll this — the canonical file is the reference.

Secrets.swift is the credentials enum (enum Secrets { static let appID = "..."; static let region = "..."; static let authKey = "..." }) populated by Step 2c provision. Added to .gitignore.

SwiftUI vs UIKit hosts. The template above is the SwiftUI host. For pure UIKit apps, skip UIViewControllerRepresentable and present UINavigationController(rootViewController: CometChatConversations()) directly in SceneDelegate — see CometChatBuilderSwift/BuilderApp/SceneDelegate.swift (inside the Ios Visual Builder ZIP at https://preview.cometchat.com/downloads/cometchat-builder-ios.zip) + View Controllers/HomeScreenViewController.swift for the canonical UIKit pattern.

Calls + builder

If CometChatBuilderSettings.shared.callFeatures has any enabled feature: 1. Init Calls SDK at the same site as UI Kit (see cometchat-ios-calls) 2. Mount CometChatIncomingCall at app root (SwiftUI App's WindowGroup root, or UIKit's keyWindow.rootViewController overlay — the builder repo's BuilderApplication-equivalent pattern in SceneDelegate.swift is the reference) 3. PushKit + CallKit wiring — defer to cometchat-ios-push

What is NOT honored in v1

The builder repo's HomeScreenViewController is a UITabBarController with up to 4 tabs (Chats / Calls / Users / Groups) driven by CometChatBuilderSettings.shared.layout.tabs. Skills' thin wrapper emits a single conversations surface, not the tabbed shape. Theme color + typography + chat-feature toggles ARE honored. To get the tabbed shape, copy HomeScreenViewController.swift from the builder repo instead of the wrapper template above.

Related skills

Mobile Developmentfrontendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.