The iOS app
The app is native SwiftUI for iOS 17 and later, in
ios/. It signs in with Amazon
Cognito (through the Amplify library) and talks to the API through a Swift client
generated from the contract.
This page is written for someone who knows programming but not SwiftUI. It starts with the few SwiftUI ideas you need, then follows the app from launch to a screen on the phone.
SwiftUI in five ideas
- A
Viewis a struct that describes UI. Itsbodyreturns other views. SwiftUI callsbodyagain whenever data the view reads changes, and redraws only what changed. You never "update the screen" yourself. @Stateis a value a view owns, like a local variable that survives redraws.@Observableclasses are models. A view that reads a model's property redraws when that property changes. In this app, each screen's logic and loading lives in a model class, and the view only draws it.@Environmentpasses values down the view tree without threading them through every initializer. The app uses it for app-wide actions such as "push this screen" or "open Quick log"..task { … }runs async work when a view appears and cancels it when the view goes away. This is where screens load their data.
From launch to a screen
-
CaregiverApp.swiftis the entry point (@main). It configures Amplify fromamplifyconfiguration-dev.jsonin Debug builds or-prod.jsonin Release, creates the oneSession, and showsRootView. -
Session.swiftdecides where the caregiver is.refresh()checks for a Cognito session and callsGET /v1/me, then sets one of four states:checking,signedOut,noTeam(account)orready(account). -
RootView.swiftswitches on that state: the auth screens, Join a care team, or the signed-in app. It also offers Face ID after a password sign-in. -
TabShell.swiftis the signed-in app: the tab bar (Home, Insights placeholder, Team, Settings) and the ⊕ button. It owns the models shared across tabs, such as the active care receiver, and publishes app-wide actions through the environment:Environment value What it does pushRoutePush a screen onto Home's stack. popToHome,popToTrackersGo back to the root, or to the Trackers list. quickLogOpen Quick log; quickLogRunstells screens when it saved.homeWrote,homeWritesTell Home an entry or note was edited or deleted. receiverChangedA care receiver was renamed, archived or restored.
Navigation: one stack, one list of routes
Home's tab holds one NavigationStack, driven by an array of
Route
values. Route is an enum with one case per pushable screen: trackers, tracker, schedules,
careReceiver, entry, journalNote and comingUp. Pushing a screen means appending a Route;
going back means removing it. routeDestinations(...) maps each case to its view, in one place.
The stack is kept to one path of values on purpose. SwiftUI misorders a stack that mixes this style
with other ways of pushing, so a tap would flash and Back would show the wrong screen. Sheets
(Add tracker, Quick log, confirmations) are presented with .sheet on the screen that opens them,
and are not part of the path. Team and Settings each have a simpler stack of their own.
A screen: View, Model, Service
Every area folder follows the same three-part shape:
| Part | Example | Job |
|---|---|---|
| View | TrackerDetailView | Draws the screen from the model, and turns taps into model calls or pushes. |
| Model | TrackerDetailModel (@Observable) | Holds the screen's state (phase: .loading / .loaded / .failed) and does the async work. |
| Service | TrackersService | A struct of async closures, one per API call. .live(client) calls the API; tests and previews pass fakes. |
Services being plain closures is what makes the app testable: a test builds a model with a service
whose closures return canned data, so there are no network calls and no mocking framework. Previews
do the same, with data from each area's …Fixtures.swift (the people and trackers are described in
ios/fixtures.md).
Worked example: opening a tracker
What happens when a caregiver taps a tracker on the Trackers list:
- The tap. In
TrackersView.swifteach row is aNavigationLink(value: Route.tracker(id:receiver:)), which appends that route to the stack's path. - The destination.
routeDestinationsinRoute.swiftmaps.trackertoTrackerDetailView(trackerID:receiver:service:). - Loading. The view's
.taskcreates aTrackerDetailModeland callsload(). The model starts in.loading, so the view shows a spinner. - The API call.
load()callsservice.trackerDetail(trackerID). The live closure inTrackersService.swiftcalls the generated client,client.getTrackerDetail(path:), which isGET /v1/trackers/{trackerId}. The API side is the same request from the server's point of view. - The response. The generated client returns one case per documented response (
.ok,.notFound,.forbiddenand so on). The service turns.okinto the app'sTrackerProfile, and any other case into anAppError. - Drawing. The model sets
phase = .loaded(profile). Because the view readsphase, SwiftUI redraws it with the tracker's details.
Talking to the API
- The generated client.
CaregiverAPIis a local Swift package inshared/types-swift. Apple's swift-openapi-generator builds it from a copy of the contract during the Xcode build, so there is no generated Swift in the repo. EachoperationIdin the contract becomes a method, likegetTrackerDetail. APIClient.swiftbuilds the client with the base URL and a chain of middleware.AuthMiddleware.swiftaddsAuthorization: Bearer <ID token>to every request, usingCognitoTokenProvider.- The base URL comes from
API_BASE_URLinInfo.plist, which is set per build fromios/Config/Dev.xcconfigandProd.xcconfig(read byAppConfig.swift).
Folder map
| Folder | What is in it |
|---|---|
App/ | The entry point and RootView. |
Auth/ | Landing, Sign in, Sign up, confirm code, reset password, Face ID. |
GettingIn/ | Join a care team and Create your first care team, after sign-in. |
Home/ | Home, the tab shell, Quick log, Entry detail, journal notes, Coming up. |
Trackers/ | The Trackers list, Tracker detail, Add and Edit tracker, schedules, and Route. |
Team/ | Team, Care team, Care receiver, invitations, coverage. |
Settings/ | Settings, notifications, close account, sign out, about. |
Support/ | Session, the API client and its middleware, errors, Keychain, Face ID, server clock. |
DesignSystem/ | Shared Stride… components and Theme (colors, type, spacing), cataloged in ios/design-system.md. |
Resources/ | Assets and the Amplify configuration files. |
Tests are in ios/CaregiverTests/, one file per model or area (XCTest).
Building and running
The Xcode project is generated from
ios/project.yml by
XcodeGen, and the .xcodeproj is not committed. After pulling, or after editing project.yml:
cd ios && xcodegen generate && open Caregiver.xcodeproj
Run the tests from the command line:
cd ios && xcodegen generate && xcodebuild test \
-scheme Caregiver -destination 'platform=iOS Simulator,name=iPhone 17' \
-skipPackagePluginValidation
-skipPackagePluginValidation is needed on every xcodebuild, because the generated client is
built by a package plugin. A Debug build talks to the dev API; a Release build talks to prod. CI
builds and tests the app on pull requests that touch ios/.