Swift tutorial
Lily's semantics, accessibility contracts and worldwide rules for SwiftUI on iPhone and iPad: every word is yours, every native control stays Apple's, and a style changes how a component looks, never what VoiceOver reads.
What you'll build
A small contact form — a labelled field with a hint and an error, an error summary, a warning — first plain, then themed, in about 15 minutes.
Early. Version 0.1.0 is a first slice, not the whole catalog: see the list in step 2. It is published as a git tag, so add it by URL as in step 1.
Before you start
You need Xcode 16 or later, Swift 6 language mode, and an app that targets iOS 18 or iPadOS 18 or later. Lily has no third-party runtime dependency.
Step 1 — Add the package
In Xcode choose File ▸ Add Package Dependencies… and enter the repository URL, or, in a Swift package:
// Package.swift
dependencies: [
.package(url: "https://github.com/LilyDesignSystem/lily-design-system-swift.git", from: "0.1.0"),
],
targets: [
.target(name: "App", dependencies: [
.product(name: "LilyUI", package: "lily-design-system-swift"),
.product(name: "LilyThemes", package: "lily-design-system-swift"),
]),
], The repository is a read-only export of the monorepo's lily-design-system-swift folder;
issues and pull requests go to the monorepo.
The products are LilyCore (pure Swift: search folding, middle truncation,
clinical formatting), LilyUI (the SwiftUI components), LilyThemes (generated tokens and the themed styles) and LilyUIExamples (a worked example of every component).
Step 2 — Your first component
import SwiftUI
import LilyUI
struct Notice: View {
var body: some View {
WarningText(prefix: "Warning", text: "You can be fined up to £5,000 if you do not register.")
}
} WarningText keeps the prefix and the text together so VoiceOver reads them as
one sentence. The first slice has Field, ErrorSummary, SummaryList, WarningText, LilyAlert, Badge, Tag, Card, InsetText, the
clinical views (ObservationView, AgeView, MedicationView and others) and the International Patient Summary. Lily ships no button,
toggle, picker, date picker, sheet, alert or navigation: those stay SwiftUI's.
Step 3 — Compose a small form
import SwiftUI
import LilyUI
struct ContactForm: View {
@State private var name = ""
@State private var nameError: String?
var body: some View {
Form {
if let nameError {
ErrorSummary(title: "There is a problem", problems: [.init(nameError) { /* focus the name field */ }])
}
Field(label: "Full name", description: "As it appears on your passport", error: nameError,
required: true, requiredLabel: "required") {
TextField("", text: $name).textContentType(.name)
}
WarningText(prefix: "Warning", text: "You can be fined up to £5,000 if you do not register.")
Button("Save") {
nameError = name.isEmpty ? "Enter your full name" : nil
}
}
}
} Field draws the visible label, the hint and the error, and gives the control
one spoken name that joins them. The control inside is SwiftUI's own TextField. ErrorSummary lists the problems and calls each one's closure
when it is activated, so you can move focus to the field.
Verified 2026-11-22: this form, the theme in step 5 and the catalog in
step 6 were compiled against the package with swift build, and the
package's own tests pass with swift test. The accessibility audit of the
example app runs in Xcode (see step 6).
Step 4 — The Swift idioms
- Every word is yours. Lily has no default text and looks nothing up in
its own bundle: the labels, hints and errors are
Stringparameters shown withText(verbatim:), so the form speaks your app's language. - Change the look with a style, never by wrapping. A style receives a
configuration and draws it:
.fieldStyle(MyFieldStyle()). The accessibility label, hint, traits and announcements stay outside the style, so no style can change what VoiceOver says. - The system owns the rest. Dynamic Type, Reduce Motion, contrast and language are the system's; no component reads or overrides them except to adapt.
- Spoken joins are line breaks. Where Lily joins two strings for VoiceOver it uses a line break, never a word or punctuation of its own.
Step 5 — Theme it
Add LilyThemes and set the tokens once, near the root:
import LilyThemes
struct Root: View {
@Environment(\.colorScheme) private var colorScheme
var body: some View {
ContactForm()
.lilyTheme(colorScheme == .dark ? .dark : .govUk)
}
} The tokens are .light, .dark, .nhsEnglandPatients, .govUk, .uswds and .japanDigitalAgency, generated
from the same token files as the web themes. The themed styles use only the colour pairs the
web themes gate at 4.5:1; a severity colour is a rail or a border, never text. Using a
public-sector theme does not make your app that body's service: supply your own name and
marks.
Step 6 — See it all working
LilyUIExamples is a worked example of every component and a searchable catalog you
can host in any app:
import LilyUIExamples
@main struct CatalogApp: App {
var body: some Scene {
WindowGroup { ExampleCatalog(title: "Components", searchPrompt: "Search components") }
}
} Or run the iOS example app, which runs Apple's accessibility audit on the catalog and on every component's screen at the default and the largest text size:
cd lily-design-system/lily-design-system-swift-examples
xcodebuild -project LilyExamples.xcodeproj -scheme LilyExamples \
-destination 'generic/platform=iOS Simulator' build Next steps
- Kotlin tutorial — the same components for Jetpack Compose on Android.
- Component catalog — the web contract each Swift component follows, with ARIA and keyboard per component.
- Worldwide — why Lily ships no default text and no single-region default.
- Getting started in five minutes — the same start on the web.
Questions along the way? The help page is full of answers — and if a step could be clearer, tell us and we'll gladly improve the tutorial.