skills/generators/state-restoration/SKILL.md
Generates state preservation and restoration infrastructure for navigation paths, tab selection, scroll positions, and form data across app launches and background termination. Use when user wants to save/restore app state, remember where the user left off, or persist UI state.
npx skillsauth add rshankras/claude-code-apple-skills state-restorationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Generate production state restoration infrastructure that saves and restores app state (selected tab, scroll position, navigation path, form data) across launches and background termination. Uses Codable state models, @SceneStorage, @AppStorage, and custom file-based persistence.
Use this skill when the user:
Search for existing state restoration:
Glob: **/*StateRestoration*.swift, **/*AppState*.swift, **/*SceneStorage*.swift
Grep: "SceneStorage" or "NavigationPath" or "selectedTab" or "scrollPosition"
If existing state management found:
Determine which navigation pattern the app uses:
Grep: "NavigationStack" or "NavigationSplitView" or "TabView" or "NavigationLink"
This affects which restoration components to generate.
Ask user via AskUserQuestion:
What state to restore? (multi-select)
Storage method?
Restore behavior?
Read templates.md for production Swift code.
Generate these files:
AppState.swift — Codable struct capturing all restorable stateStateRestorationManager.swift — @Observable manager with auto-save and restoreBased on configuration:
3. NavigationStateModifier.swift — If navigation path selected
4. ScrollRestorationModifier.swift — If scroll position selected
5. TabRestorationModifier.swift — If tab selection selected
6. FormDraftManager.swift — If form data selected
Check project structure:
Sources/ exists -> Sources/StateRestoration/App/ exists -> App/StateRestoration/StateRestoration/After generation, provide:
StateRestoration/
├── AppState.swift # Codable state model
├── StateRestorationManager.swift # Auto-save/restore orchestrator
├── NavigationStateModifier.swift # Navigation path persistence (optional)
├── ScrollRestorationModifier.swift # Scroll position persistence (optional)
├── TabRestorationModifier.swift # Tab selection persistence (optional)
└── FormDraftManager.swift # Form draft auto-save (optional)
Basic setup in App struct:
@main
struct MyApp: App {
@State private var stateManager = StateRestorationManager()
var body: some Scene {
WindowGroup {
ContentView()
.environment(stateManager)
}
}
}
Restore navigation path:
struct ContentView: View {
@Environment(StateRestorationManager.self) private var stateManager
var body: some View {
@Bindable var sm = stateManager
NavigationStack(path: $sm.navigationPath) {
HomeView()
.navigationDestination(for: Route.self) { route in
RouteView(route: route)
}
}
.modifier(NavigationStateModifier(stateManager: stateManager))
}
}
Restore tab selection:
struct MainTabView: View {
@Environment(StateRestorationManager.self) private var stateManager
var body: some View {
@Bindable var sm = stateManager
TabView(selection: $sm.selectedTab) {
HomeTab().tag(0)
SearchTab().tag(1)
ProfileTab().tag(2)
}
.modifier(TabRestorationModifier(stateManager: stateManager))
}
}
Restore scroll position:
struct ItemListView: View {
let items: [Item]
var body: some View {
ScrollView {
LazyVStack {
ForEach(items) { item in
ItemRow(item: item)
}
}
}
.modifier(ScrollRestorationModifier(scrollViewID: "item-list"))
}
}
Auto-save form drafts:
struct ComposeView: View {
@State private var draftManager = FormDraftManager(formID: "compose")
@State private var title = ""
@State private var body = ""
var body: some View {
Form {
TextField("Title", text: $title)
TextEditor(text: $body)
}
.onAppear { draftManager.restore(into: &title, &body, keys: "title", "body") }
.onChange(of: title) { draftManager.save(key: "title", value: title) }
.onChange(of: body) { draftManager.save(key: "body", value: body) }
.onSubmit { draftManager.clearDraft() }
}
}
@Test
func stateRestoredFromDisk() async throws {
let manager = StateRestorationManager(storage: .file(directory: tempDir))
manager.selectedTab = 2
manager.saveState()
let restored = StateRestorationManager(storage: .file(directory: tempDir))
restored.restoreState()
#expect(restored.selectedTab == 2)
}
@Test
func timeLimitedRestoreExpires() async throws {
let manager = StateRestorationManager(
storage: .file(directory: tempDir),
restoreBehavior: .timeLimited(minutes: 30)
)
// Simulate state saved 60 minutes ago
manager.appState.lastSavedDate = Date().addingTimeInterval(-3600)
manager.saveState()
let restored = StateRestorationManager(
storage: .file(directory: tempDir),
restoreBehavior: .timeLimited(minutes: 30)
)
restored.restoreState()
#expect(restored.selectedTab == 0) // Default, not restored
}
@Test
func formDraftClearedOnSubmit() async throws {
let draft = FormDraftManager(formID: "test", storage: .file(directory: tempDir))
draft.save(key: "title", value: "My Draft")
#expect(draft.value(for: "title") == "My Draft")
draft.clearDraft()
#expect(draft.value(for: "title") == nil)
}
enum Route: Codable, Hashable {
case detail(id: UUID)
case settings
case profile(userID: String)
}
// NavigationPath supports Codable serialization
let representation = navigationPath.codable
let data = try JSONEncoder().encode(representation)
// Use String tags instead of Int for readability and stability
TabView(selection: $stateManager.selectedTab) {
HomeView().tag("home")
SearchView().tag("search")
ProfileView().tag("profile")
}
// Save draft only after user pauses typing (1 second)
.onChange(of: textContent) {
draftManager.save(key: "content", value: textContent)
// Internally debounced — won't write to disk on every keystroke
}
NavigationPath.CodableRepresentation converted to Data.scenePhase). Force quit from the app switcher does NOT trigger scenePhase change on iOS. Save state on every significant change, not just on backgrounding.stateVersion field for breaking changes.generators/persistence-setup — Core Data / SwiftData persistence layergenerators/deep-linking — URL-based navigation restorationdevelopment
US web checkout via the StoreKit External Purchase Link entitlement — currently 0% Apple commission (litigation ongoing), how to ship it safely, and how to architect for a commission flip so a future ruling is a config change, not a rewrite. Use when adding external purchase links, weighing web checkout vs IAP, or planning US-storefront pricing strategy.
tools
Revenue beyond the single-app price tag — own-app bundles, Family Sharing as a conversion lever, cross-developer bundles & suites, and institutional licensing via Group Purchases / Apple School & Business Manager. Use when a developer has multiple apps, a subscription worth sharing, complementary indie partners, or school/clinic/business buyers.
testing
Run a structured accessibility audit on an iOS/macOS app — automated XCUITest audits, Accessibility Inspector, manual VoiceOver/Dynamic Type passes, and App Store Accessibility Nutrition Label evaluation. Use before release, when preparing Nutrition Label declarations, or for EU Accessibility Act compliance.
tools
Stage-by-stage audit of an app's App Store growth machinery against a 54-item P0–P9 playbook — every item scored from an App Store Connect MCP call, a codebase check, or an explicit question to the user, then routed to the skill or command that fixes it. Read-only on App Store Connect. Use for a growth audit or scorecard, a pre-launch growth plan, a quarterly re-audit, or "which growth levers am I missing."