iOS (Swift)
The iOS SDK renders surveys with SwiftUI. Initialise once, attach a host, and present surveys by identifier.
Installation
Section titled “Installation”WhiskrKit is distributed via Swift Package Manager. In Xcode, choose File → Add Package Dependencies, enter https://github.com/whiskrkit/whiskrkit-swift.git, and set the dependency rule to Up to Next Major Version.
WhiskrKit.shared
Section titled “WhiskrKit.shared”The singleton entry point for all SDK interactions. All methods must be called on the main actor.
initialize(apiKey:withMockedSurveys:)
Section titled “initialize(apiKey:withMockedSurveys:)”Initialises the SDK. Must be called before any other WhiskrKit method, typically in your App init.
WhiskrKit.shared.initialize( apiKey: "wk_live_your_api_key", withMockedSurveys: false)| Parameter | Type | Description |
|---|---|---|
apiKey | String | Your WhiskrKit API key from the dashboard: a test key for debug builds, a live key for releases (more) |
withMockedSurveys | Bool | Use mock data for local testing without hitting the API, the default is set to false |
When withMockedSurveys is true, the SDK uses a local MockConfigurationService and bypasses all network calls. Useful during development and UI testing.
setTheme(_:)
Section titled “setTheme(_:)”Applies a visual theme to all survey UI. Call after initialize.
WhiskrKit.shared.setTheme(.systemStyle)| Parameter | Type | Description |
|---|---|---|
theme | WhiskrKitTheme | The theme to apply |
From 0.3.0, a toast’s own title and description can have their own text styles, separate from the question title. Set them on the toast container; left out, they use the headline and subheadline:
var theme = WhiskrKitTheme.systemStyletheme.container?.toast?.title = .init(font: .footnote.weight(.semibold), color: .secondary)WhiskrKit.shared.setTheme(theme)present(surveyId:)
Section titled “present(surveyId:)”Imperatively presents a survey, bypassing eligibility checks.
WhiskrKit.shared.present(surveyId: "nps-survey")| Parameter | Type | Description |
|---|---|---|
surveyId | String | The identifier of the survey to present |
Requires at least one view in the hierarchy with .whiskrKit() attached. If none is present, this is a no-op.
checkAndPresent(surveyId:)
Section titled “checkAndPresent(surveyId:)”Checks eligibility and presents a survey if the user qualifies. The timing is yours; the targeting decision stays with the backend.
WhiskrKit.shared.checkAndPresent(surveyId: "settings-feedback")| Parameter | Type | Description |
|---|---|---|
surveyId | String | The identifier of the survey to evaluate and potentially present |
Requires at least one view in the hierarchy with .whiskrKit() attached. If eligibility fails, this is a no-op.
onSurveyCompleted
Section titled “onSurveyCompleted”Called each time the user submits a survey, for example to log it in your own analytics or to move on in a flow. Available from 0.2.0.
WhiskrKit.shared.onSurveyCompleted = { completion in analytics.log("survey_completed", ["survey": completion.surveyId])}| Property | Type | Description |
|---|---|---|
surveyId | String | The identifier of the submitted survey |
answers | [SurveyCompletion.Answer] | The submitted answers, ordered by question id. Each has a questionId, a questionType (scaleRating, symbolRating, thumbsRating, textualSurvey or multipleChoice) and a value (.score, .thumbs(isUp:), .text or .choices). Unanswered questions are left out. |
Runs on the main actor as soon as the user submits, whether or not the response reaches the server (a failed submission is queued and retried). It is not called when a survey is dismissed without submitting, and it is also called with mocked surveys.
Attributes
Section titled “Attributes”Attach context about the current user or session to every survey response submitted afterwards, such as the user’s plan or an experiment variant. They’re stored with each response; see Attributes for what to send and what not. Attributes are held in memory only, so set them again at launch. Available from 0.2.0.
WhiskrKit.shared.setAttribute("plan", "pro")WhiskrKit.shared.setAttribute("sessions", 3)WhiskrKit.shared.setAttributes(["tier": "gold", "beta": true]) // mergesWhiskrKit.shared.setAttribute("plan", nil) // removes oneWhiskrKit.shared.removeAttribute("tier")WhiskrKit.shared.clearAttributes()Values are strings, numbers or bools. Limits: 20 attributes, keys of 1 to 64 characters, string values up to 256 characters and 2 KB in total; the SDK trims anything beyond.
Survey language
Section titled “Survey language”WhiskrKit’s own strings (the submit button, “required” and the accessibility labels) follow the language the survey was served in, so they match your question text. Without a language from the server they follow the app’s language. Built-in strings are translated into English, Dutch, German, French, Spanish, Italian, Portuguese (Brazil), Japanese, Korean and Simplified Chinese. Available from 0.2.0.
Rating metrics
Section titled “Rating metrics”Rating questions show the colours, end labels and display style of their metric (NPS, CSAT, CES or custom). There is nothing to configure in your app; see Rating metrics. Available from 0.3.0.
WhiskrKit branding
Section titled “WhiskrKit branding”On the Free plan, toasts and sheets show a small “Powered by WhiskrKit” line below the submit button. The server decides when it appears; there is nothing to configure in your app. It adapts to your theme and dark mode, and is hidden on paid plans.
View modifiers
Section titled “View modifiers”.whiskrKitSurvey(identifier:)
Section titled “.whiskrKitSurvey(identifier:)”Automatically evaluates eligibility and presents a survey when the modified view appears.
HomeView() .whiskrKitSurvey(identifier: "nps-survey")| Parameter | Type | Description |
|---|---|---|
identifier | String | The survey identifier from the dashboard |
.whiskrKit()
Section titled “.whiskrKit()”Registers a view as the attachment point for imperatively triggered surveys. Does not perform eligibility checks on its own.
ContentView() .whiskrKit()Apply once, high in your view hierarchy.
Platform requirements
Section titled “Platform requirements”| Platform | Minimum version |
|---|---|
| iOS | 17.0 |
| iPadOS | 17.0 |