/apple-dev-skills:swiftui-navigation-architecturefrom apple-dev-skills
Wires SwiftUI navigation as data with an observable Router, typed Route enums, NavigationStack, sheets, deep links, and Codable restoration. Use when setting up app navigation, adding deep links, or migrating off NavigationView.
Ships in apple-dev-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The default navigation shape for Apps on this catalog's baseline (apple-platform-targets: iOS 26 / macOS 26, Swift 6 language mode): navigation state is data — a typed route enum in one observable router — so flows are unit-testable (assert on [Route]), deep-linkable (URL → routes is a pure function), and restorable (routes are Codable).
NavigationView or view-payload NavigationLink(destination:)Owns container choice (Stack / SplitView / Tab), route modeling, the router object, deep-link funneling, and restoration. Does NOT own: known interaction bugs in nav components → swiftui-interaction-footguns; injecting the services destination views need → swift-dependency-injection; nav-chrome accessibility → ios-accessibility-engineering.
| App shape | Container |
|---|---|
| Single drill-down flow (iPhone-first) | NavigationStack(path:) |
| 2–5 top-level peer sections | TabView + one NavigationStack per tab, each with its own path |
| Source list → detail (iPad / Mac) | NavigationSplitView; sidebar selection is router state, the detail column hosts its own NavigationStack |
Never NavigationView in new code — superseded by NavigationStack / NavigationSplitView since iOS 16, deprecated in the iOS 27 SDK (Xcode 27 warns; the Xcode 26 SDK does not).
enum Route: Hashable, Codable {
case board(id: UUID) // payloads are IDs, not model objects
case settings
}
enum Modal: String, Identifiable { // presentation is NOT navigation
case paywall, onboarding
var id: String { rawValue }
}
@Observable @MainActor
final class Router {
var path: [Route] = []
var modal: Modal?
// One pure mapping: URL → navigation state. Unit-test without UI.
func open(_ url: URL) {
guard url.scheme == "myapp" else { return }
switch url.host {
case "board": path = [.board(id: UUID(uuidString: url.lastPathComponent) ?? UUID())]
case "settings": path = [.settings]
default: break
}
}
}
@main struct MyApp: App {
@State private var router = Router()
var body: some Scene {
WindowGroup {
NavigationStack(path: $router.path) {
HomeView()
.navigationDestination(for: Route.self) { route in
switch route { // exhaustive — compiler catches new routes
case .board(let id): BoardView(id: id)
case .settings: SettingsView()
}
}
}
.environment(router)
.sheet(item: $router.modal) { ModalHost($0) }
.onOpenURL { router.open($0) }
}
}
}
Rules the shape encodes:
NavigationLink(value:) or router.path.append(...); never NavigationLink(destination:) in a path-managed stack (those pushes bypass path, desyncing back-stack, deep links, and restoration).navigationDestination(for:) on the stack's root content, outside lazy containers. Apple's docs (navigationDestination(for:destination:)): "Do not put a navigation destination modifier inside a 'lazy' container, like List or LazyVStack. … Add the navigation destination modifier outside these containers so that the navigation stack can always see the destination."[Route] over NavigationPath — pattern-matchable, exhaustively switched, Codable for free.item:-driven; one optional per presentation kind — sheet, cover, alert. Parallel isPresented: Bools race and can present blank); a presented flow is never a Route case. Which kind → next section.@MainActor (it is UI state; Swift 6 enforces it), routes are Hashable + Codable value types. On Xcode 26's default MainActor isolation (SE-0466) this is implicit for a new project's modules — keep the explicit annotation anyway so the class stays correct if the module later turns default isolation off."Where does the user land when this closes?" is decided by the semantic you pick, not by the destination view. Pick the tag first; the API and its back/dismiss behavior follow.
| Semantic | API | Dismissal | iOS / iPadOS | macOS |
|---|---|---|---|---|
| push | NavigationStack + navigationDestination | back pops one level; edge-swipe on by default | — | same model, toolbar back |
| sheet | .sheet(item:) (+ .presentationDetents) | swipe-to-dismiss on by default; interactiveDismissDisabled(true) to force completion | detents resize; >1 detent shows the grabber | window-styled sheet — detents don't drive sizing, size the content itself |
| full-screen cover | .fullScreenCover(item:) | no interactive dismiss; exit only via explicit close | opaque, covers everything | unavailable on native macOS (Mac Catalyst only) — fall back to push/sheet, see below |
| popover | .popover | tap outside | collapses to a sheet in compact width unless .presentationCompactAdaptation(.popover) | always a true anchored popover |
| alert | .alert(_:isPresented:presenting:) | button tap only — no scrim tap, no swipe | data-drive off one optional | same |
| dialog | .confirmationDialog | Cancel or tap outside | bottom action sheet | rendered alert-style |
| root-swap | conditional root content on @Observable state | none — the outgoing tree is destroyed | auth gates, onboarding-done | same |
Two contract rules the table enforces:
confirmationDialog or popover, never an .alert, regardless of visual intent.LoginView vs AppView at the root off auth state: success flips the flag and the login tree is destroyed; logout flips it back and tears down the entire app stack (paths, sheets, all of it). Presenting the app over login couples app lifetime to a presentation and turns logout into "dismiss a modal" with login still alive underneath.A flow covered by fullScreenCover on iOS ships as a push (or sheet) on macOS — and Close must land on the same screen on both platforms. The trap: dismiss() closes the whole cover, but the pushed variant's naive path.removeLast() pops one level and strands the user mid-flow.
extension Router {
// One flow, two containers: cover on iOS, push on macOS.
func startGame(id: UUID) {
#if os(macOS)
path.append(.board(id: id))
#else
cover = .board(id: id) // .fullScreenCover(item: $router.cover)
#endif
}
func closeGame() { // lands on the hub on BOTH platforms
#if os(macOS)
path.removeAll() // pop the whole flow — pop-one strands mid-flow
#else
cover = nil
#endif
}
}
Route both entry and exit through router methods (as above) so no view ever encodes the platform branch.
onOpenURL, universal links, NSUserActivity, notification taps) funnels into router.open(_:) at the scene root — one handler, one mapping function, unit tests assert URL → [Route] directly.scenePhase == .background, JSONEncoder the [Route] into @SceneStorage(a String slot); on launch, decode and assign. Routes that reference store objects carry IDs — resolve at display time and drop routes that no longer resolve instead of crashing.NavigationSplitView: sidebar selection lives in the router; only the detail column hosts a NavigationStack. Don't nest stacks in the sidebar.TabView: the router owns selectedTab and one path per tab — paths kept in per-view @State reset whenever tab identity churns. Selecting the already-active tab popping to root becomes a 2-line router method.swiftui-interaction-footguns..environment: a single owner instead of bindings threaded through N view layers; @Observable keeps invalidation scoped to views that actually read path.NavigationPath: exhaustive switch in navigationDestination means the compiler flags every unhandled route; NavigationPath trades that away for type erasure most single-module apps don't need.NavigationPath + its CodableRepresentation for restoration; you give up exhaustive matching.NavigationStack without router or path is fine; adopt the shape when the second entry point appears, not speculatively.UIViewController interop) → keep coordination at the UIKit layer; don't force a SwiftUI router across the hosting bridge.apple-platform-targets drop-down default) → the shape works unchanged (@Observable, NavigationStack both available; only Liquid Glass presentation chrome is unavailable).@Observable requires iOS 17.0 / macOS 14.0 as its own floor, so this is the lowest target the shape needs no changes on.ObservableObject replaces @Observable for the router.fullScreenCover is available there; the push/sheet fallback is for native (AppKit-based) macOS targets.NavigationView in new code — superseded since iOS 16, deprecated in the iOS 27 SDK (Xcode 27 warns), unpredictable column behavior. Use NavigationStack / NavigationSplitView.navigationDestination(for:) inside List / LazyVStack — the lazy container may not have created the registering view yet, so pushes silently fail (runtime console warning). Register at the stack root.NavigationLink(destination:) into a path-based stack — pushes invisible to path; back-stack count, deep links, and restoration all desync.Modal enum.@State — switching tabs (or any identity churn) resets the stack; paths belong to the router.onOpenURL sprinkled across views — multiple competing handlers; one scene-root handler feeding one mapping function.@MainActor — Swift 6 isolation errors the first time a Task mutates path; annotate the class, not call sites. (Implicit under Xcode 26's default MainActor isolation — SE-0466 — but not every module opts into that default, so annotate explicitly.)Hashable/Codable, goes stale after edits; carry IDs and resolve at display.@Environment(\.dismiss) read in the presenter — the action applies to the environment where it's declared, never to the content the presenter presented: it pops the presenter itself, closes the sheet the presenter lives in, or (macOS / iPadOS, presenter is a window's root) closes the window; only when the presenter isn't itself presented is it a no-op. Presenter-side closing = nil out the router optional.dismiss() vs dismissAll() as distinct router methods; chain a follow-up presentation in the prior one's onDismiss, never present-while-presenting.NavigationView; no NavigationLink(destination:) inside path-managed stacksRoute enum, Hashable + Codable; payloads are IDs, not model objectsnavigationDestination(for:) registered at the stack root, outside lazy containers@Observable @MainActor router in .environment; all paths (incl. per-tab) live on ititem: off router optionals (one per presentation kind), never a Route case or parallel Bools.onOpenURL at the scene root; URL → [Route] mapping has unit testsswiftui-interaction-footguns — known bugs in the nav components this skill wires togetherswift-dependency-injection — how destination views get their servicesapple-platform-targets — the iOS 26 / macOS 26 baseline this shape assumesios-accessibility-engineering — accessibility of the navigation chromereferences/official-docs.md.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub wei18/apple-dev-skills --plugin apple-dev-skills28 skills in this plugin
/ai-translated-localizationLocalization scope and AI-translation execution for Apple-platform Apps on `Localizable.xcstrings` — default locale set, source / primary language rule, per-locale review gotchas, completeness gates. Use when deciding which locales to ship at project setup; when adding or refreshing user-facing strings (UI keys, Game Center, App Store metadata) in non-source locales; when `extractionState: stale` entries or untranslated placeholder markers appear; or when asked "how many locales", "how do translations enter git". Does NOT cover RTL layout or ASC upload mechanics → asc-api-automation./apple-platform-targetsDefault minimum deployment target for Apple-platform Swift Apps — iOS 26 / macOS 26 on the Xcode 26 toolchain (Swift 6 language mode) — and how to deviate down (iOS 18 / 17) or up. Use when starting a new Apple-platform project, writing the Package.swift `platforms:` list, deciding whether an API newer than the floor is worth bumping for or a client requirement forces dropping below it, or when asked "what should the minimum iOS / macOS version be". Entry point of the bootstrap chain; does NOT own language mode → swift6-concurrency, or module layout → swiftpm-modularization./apple-public-repo-securityUse when a repo goes public or open-sources, when a CloudKit server-to-server PEM, ASC API `.p8`, APNs key, signing `.p12`, or provisioning profile first enters the pipeline, or when asked how to prevent or respond to a secret leak (gitleaks, lefthook, GitHub Secret Scanning, `git filter-repo`, rotate-first). Also for Apple upstream telemetry disclosure (MetricKit, Game Center, sysdiagnose). Repo-hygiene baseline only; ship-in-binary identifiers (AdMob IDs via xcconfig) and CLI keys in `secrets/.env` are build-time-secret-injection; ASC API usage is asc-api-automation./apple-three-piece-analyticsChoose analytics and metrics sources for a solo / small-team Apple app and decide whether a third-party tracking SDK is justified. Use when picking an analytics SDK; when asked "should I add Firebase / Mixpanel / Amplitude / TelemetryDeck"; when asked what App Store Connect Analytics, MetricKit (`MXMetricPayload`) or Game Center can measure without an SDK; when the analytics choice drives `PrivacyInfo.xcprivacy` or forces ATT. Does NOT own MetricKit perf wiring (ios-performance-engineering), App Review privacy-label parity (app-store-review-rejections), or sink code (telemetry-facade-pattern)./app-store-review-rejectionsUse when preparing an App Store submission, reading an App Review rejection or Resolution Center message citing a guideline number (2.1, 2.3.x, 3.1.1, 4.3, 5.1.1, 5.1.2), or a privacy-manifest upload email (ITMS-91061 / ITMS-91056, missing required-reason API), or auditing an ads + Remove-Ads IAP + CloudKit + Game Center app for the rejection classes it realistically hits: the ATT-vs-AdMob trap, privacy-label parity with `PrivacyInfo.xcprivacy`, Restore Purchases, screenshot metadata, export compliance. Maps each class to a pre-submit fix. Not the submission mechanics (asc-api-automation) nor StoreKit implementation (storekit2-iap-defaults)./asc-api-automationUse when automating App Store Connect from a script or CI via the ASC REST API (`api.appstoreconnect.apple.com`) — ASC API `.p8` key / JWT auth, TestFlight `betaGroups` / `betaBuildLocalizations`, `appStoreVersions` / `releaseType`, `reviewSubmissions`, `salesReports`, `analyticsReportRequests` — or asked "automate TestFlight / submission / release notes", "should I use fastlane", or debugging 401 NOT_AUTHORIZED / 429 RATE_LIMIT_EXCEEDED, or asked which ASC steps have no API and must be clicked by hand. API side only: build & upload → xcode-cloud-single-track-ci / local-archive-export-upload; `.p8` storage → build-time-secret-injection.Other plugins' skills for the same job