iOS
API reference
The public types of CartesianCore and CartesianUI.
CartesianCore
CartesianConfig
CartesianConfig(
vertical: Vertical, // .grocery or .apparel
baseURL: URL, // your backend; REST at <baseURL>/api, WebSocket at <baseURL>/ws
urlSession: URLSession? = nil, // your own session (cookies are never handled by URLSession)
userAgent: String? = nil, // appended to "cartesian-ios/<version>"
logger: CartesianLogger? = nil,
licenseKey: String? = nil
)swiftEvery request sends X-Cartesian-SDK: ios/<version>.
CartesianClient
@MainActor final class, ObservableObject.
.restoring, .signedOut or .signedIn(User). Published..idle, .connecting, .open, .closed. Published.itemCount, total, currency, quantity(of:). Published.products, contains(_:). Published.Methods: signIn(sessionToken:), restore(), signOut(), connect(), disconnect(), refreshThreads(), renameThread(_:name:), deleteThread(_:), refreshCart(), addToCart(_:quantity:), setCartQuantity(_:quantity:), removeFromCart(_:), clearCart(), refreshWishlist(), save(_:), unsave(_:), profile(), compare(_:), readPhotoText(jpegDataURL:).
ChatSession
@MainActor final class, ObservableObject. Published state: ChatState and suggestions: [String]; threadId; events() -> AsyncStream<ChatEvent>; eventPublisher; send(_:), stop(), newChat(), open(_:), retry(), rate(_:_:), dismissError().
Models
| Type | Notes |
|---|---|
Product | Wraps the backend JSON. id, name, brand, imageURL, price (sale price when lower), regularPrice, isOnSale, size, aisle, isSnapEligible, promoLabel, isUsual, subscript(attribute), json, toJSON(), fromJSON(_:), make(id:name:) |
ChatMessage | .user(UserMessage) or .assistant(AssistantMessage) |
AgentStep | id, title, detail, phase (.started, .completed, .failed), kind (.search, .tool, .system), tool, cached |
CartUpdate | operation, changedCount, itemCount, total, currency |
Comparison | products, rows, summary, nextStep, recommendations, prosCons |
ShopperProfile | name, facts, members |
ChatEvent | .turnStarted, .turnFinished, .productsShown, .cartChanged, .error |
CartesianError | See Headless |
SessionStore
public protocol SessionStore: AnyObject, Sendable {
func load(key: String) -> String?
func save(key: String, token: String)
func clear(key: String)
}swiftKeychainSessionStore(service:accessGroup:) (default, AfterFirstUnlockThisDeviceOnly) and InMemorySessionStore() are included.
CartesianLicense
CartesianLicense.verify(_ token:, appId:, now:) returns partner, whiteLabel, expiresAt, problem and isValid.
CartesianUI
Cartesian
| Member | |
|---|---|
configure(_:options:sessionStore:) | Create the shared client. Calling it again with the same vertical and URL returns the existing client. |
client | The shared CartesianClient |
options / update(options:) | The default options for every view |
delegate | weak var CartesianDelegate? |
host | CartesianHostState: setCart([String: Int]), setSaved(Set<String>) |
present(from:prompt:animated:) | UIKit sheet |
CartesianDelegate
@MainActor protocol; every method has a default implementation.
func onAddToCart(_ product: Product, quantity: Int)
func onOpenCart()
func onToggleSaved(_ product: Product, saved: Bool)
func onOpenWishlist()
func onProductSelected(_ product: Product)
func onCheckout(_ cart: Cart) -> Bool // return true when your app handled checkout
func onEvent(_ event: ChatEvent)
func onSignInRequired() // signed out while onlineswiftCartesianChatController
The state and actions every component works from. CartesianChatView(controller:) lets you create and keep your own.
| State | Actions |
|---|---|
chat, connection, auth, cart, wishlist | send(_:), stop(), newChat(), retry(), rate(_:_:) |
draft (read/write), drawer, error, isRetrying | addToCart(_:quantity:), setQuantity(_:_:), toggleSaved(_:) |
suggestions, starters, canSend, isDeviceOnline | openProduct(_:), openCart(), openWishlist(), showDrawer(_:), checkout() |
cartCount, savedCount, quantityInCart(_:), isSaved(_:), isBusy(_:) | saveForLater(_:), moveToCart(_:), dismissError(), retryConnection() |
features, vertical, assistantName, cartName, isWhiteLabel, license |
Views
| View | |
|---|---|
CartesianChatView(client:options:delegate:onClose:) | The chat screen |
.cartesianPanel(_:layout:client:options:delegate:onHidden:) | Adaptive panel driven by CartesianPanelState |
.cartesianPanel(isPresented:prompt:layout:…) | The same, bound to a Bool |
CartesianPanelHost(_:layout:…) { content } | Container form of the panel |
CartesianAskButton(state:visible:expanded:label:icon:prompt:containerColor:contentColor:options:) | Floating trigger |
CartesianAskBar(state:placeholder:options:) | Search-style trigger |
CartesianComponents.* | The default building blocks; see Customize |
PanelLayout: .auto, .bottomSheet, .sidePanel, .floating, .fullScreen. SheetDetent: .hidden, .half, .full.
Accessibility and offline
- Every control has a VoiceOver label; status changes (offline, reconnecting, errors) are announced.
- Text follows Dynamic Type up to accessibility size 2. The orb stops animating when Reduce Motion is on.
NWPathMonitordrives the offline pill, the offline banner during a chat and the offline screen with Try again.