Swift library for parsing and displaying Typeform questionnaires.
If you're just getting started with Typeform, be sure to check out the Developer Platform Documentation.
This library is distributed using Swift Package Manager. Add it to your project via the Xcode Package Dependencies as a dependency within your Package.swift
manifest:
let package = Package(
...
// Package Dependencies
dependencies: [
.package(url: "https://github.com/Nice-Healthcare/typeform-swift.git", .upToNextMajor(from: "0.3.0"))
],
...
// Target Dependencies
dependencies: [
.product(name: "Typeform", package: "typeform-swift")
]
)
This library contains multiple modules which comprise a complete toolset for decoding, logic parsing, and display of Typeform questionnaires.
This module contains the Typeform schema and additional models for navigating the logic and completion of a form. Start with the Form
structure, which is the entity retrieved from the Typeform API.
Forms contain Field
s and Logic
which act up the fields. Given a particular Position
- the screen presented or question being asked - and Responses
- answers given to previous questions - the next position can be determined.
let form = Form()
let position = Position.screen(form.firstScreen!)
let responses: [Reference: ResponseValue] = [:]
let nextPosition = try form.next(from: position, given: responses)
This module is used primarily internal to the library. It provides some example resources for decoding/parsing tests as well as references to support SwiftUI previews.
The TypeformUI module is a SwiftUI implementation used to display and navigate through a Typeform questionnaire. It is designed to be self-contained and customizable to fit in with your apps design.
The FormView
is initialized with a Form
and a Conclusion
function/lambda callback. In most cases, the conclusion will include the responses given by the individual questioned. (The only instance where they are not provided is the canceled
case.)
struct MyView: View {
let form: Form
@State private var presentForm: Bool = false
var body: some View {
Button {
presentForm = true
} label: {
Text("Present Form")
}
.sheet(isPresented: $presentForm) {
NavigationView {
FormView(form: form) { conclusion in
presentForm = false
// handle conclusion
}
}
.navigationViewStyle(.stack)
.interactiveDismissDisabled()
}
}
}
Note, this library is incomplete; not every question type or condition has been implemented. Want to help fix a bug or make improvements? Consider becoming a contributor!
All of the structural components are supported: Welcome Screen, Ending, Statement, and Question Group. Learn more about Typeform Question Types. The currently supported types are:
- Date
- Short Text
- Long Text
- Number
- Rating
- Multiple Choice
- Yes/No
- Dropdown
- Opinion Scale
Every app is unique, so the ability to customize the look and feel of the questions presentation was built in to the library from the start.
The TypeformUI.Settings
structure allows for the customization of several aspects of the libraries interface presentation & localization.
There are several navigation styles available:
Four typography styles are used in the UI presentation and can be customized through Settings.Typography
. Each typography style can be set with a SwiftUI.Font
and SwiftUI.Color
.
Title Font | Prompt, Caption & Body Fonts |
---|---|
![]() |
![]() |
The 'Title' font is used primarily on Welcome Screens, Thank-You/Ending Screens, and Statement Fields.
Many other elements can be configured including colors, borders, padding, and spacing.
A form can further be customized by providing an optional header and/or footer. These are completely custom views that will be displayed along with each field (question).