Configuration
Configure the FlwKit iOS SDK and display flows in your app.
Basic setup
Call FlwKit.configure() once at app startup. Place it in your @main App init() or AppDelegate.application(_:didFinishLaunchingWithOptions:) — before any view appears.
configure() triggers a background prefetch of the active flow immediately. By the time a user reaches FlwKitFlowView, the flow is typically already cached and renders with no loading state.
FlwKit.configure()
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | String | Yes | — | Your app's API key from the dashboard. |
userId | String? | No | nil | Stable identifier for the current user. Used to tie analytics events and A/B test assignments to a specific user. Pass nil to use an anonymous session. |
baseURL | String? | No | https://api.flwkit.com | Override the API base URL. Only needed when self-hosting the FlwKit backend. |
FlwKitFlowView
Add FlwKitFlowView to any SwiftUI view. The active flow is fetched automatically.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
attributes | [String: Any] | No | [:] | Key-value data passed into the flow. Accessible in conditional transitions via attributes.{key}. |
onComplete | ((FlwKitCompletionResult) -> Void)? | No | nil | Called when the flow reaches a terminal complete action. |
onExit | (() -> Void)? | No | nil | Called when the user exits mid-flow. |
FlwKitCompletionResult
| Property | Type | Description |
|---|---|---|
flowId | String | The flow key identifier. |
variantId | String? | A/B test variant ID, or nil if the user was not in a test. |
completedAt | Date | Timestamp of completion. |
answers | [String: Any] | All answers keyed by block key. Choice answers are mapped to option labels, not raw values. |
FlwKit.present() — UIKit
Use FlwKit.present() to get the flow view programmatically and embed it in a UIHostingController.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
attributes | [String: Any] | No | [:] | Same as FlwKitFlowView.attributes. |
onComplete | (FlwKitCompletionResult) -> Void | No | no-op | Same as FlwKitFlowView.onComplete. |
onExit | (() -> Void)? | No | nil | Same as FlwKitFlowView.onExit. |
completion | (Result<AnyView, Error>) -> Void | Yes | — | Receives the flow view or an error. |
Error handling
All errors conform to LocalizedError. Check error.localizedDescription for a human-readable message.
When flowNotFound or a network error occurs, the SDK automatically falls back to the most recently cached flow. The error is only surfaced if no cache exists.
Caching
The SDK caches the active flow in UserDefaults after the first successful fetch.
| Situation | Behavior |
|---|---|
| Cache exists on launch | Flow renders immediately; cache refreshes in the background. |
| No cache, network available | Flow fetches with a loading indicator. |
| No cache, network unavailable | FlwKitFlowView shows an error state with a retry button. |
User progress (current screen and answers) is also persisted and restored automatically if the user closes the app mid-flow.