# State Restoration

Generates state preservation and restoration infrastructure for navigation paths, tab...

- Repository: https://github.com/rshankras/claude-code-apple-skills (846 stars)
- Category: Design
- License: MIT
- Last updated: 2026-07-24
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add rshankras/claude-code-apple-skills --skill state-restoration -g -a claude-code -y`
Codex: `npx skills add rshankras/claude-code-apple-skills --skill state-restoration -g -a codex -y`
Cursor: `npx skills add rshankras/claude-code-apple-skills --skill state-restoration -g -a cursor -y`
Gemini CLI: `npx skills add rshankras/claude-code-apple-skills --skill state-restoration -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add rshankras/claude-code-apple-skills`

## Description

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.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# State Restoration Generator

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.

## When This Skill Activates

Use this skill when the user:
- Asks to "add state restoration" or "restore state"
- Wants to "save app state" or "persist UI state"
- Mentions "preserve navigation" or "remember navigation path"
- Asks to "remember scroll position" or "restore scroll position"
- Wants the app to "resume where left off" or "remember where I was"
- Asks about "saving form drafts" or "preserve form data"
- Mentions "tab selection persistence" or "remember selected tab"

## Pre-Generation Checks

### 1. Project Context Detection
- [ ] Check Swift version (requires Swift 5.9+)
- [ ] Check deployment target (iOS 17+ / macOS 14+ for @Observable)
- [ ] Check for existing state saving code
- [ ] Identify source file locations

### 2. Conflict Detection
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:
- Ask if user wants to replace or extend it
- If extending, integrate with the existing approach

### 3. Navigation Pattern Detection
Determine which navigation pattern the app uses:
```
Grep: "NavigationStack" or "NavigationSplitView" or "TabView" or "NavigationLink"
```

This affects which restoration components to generate.

## Configuration Questions

Ask user via AskUserQuestion:

1. **What state to restore?** (multi-select)
   - Navigation path (back stack, detail selection)
   - Selected tab (TabView selection)
   - Scroll position (list/scroll view offset)
   - Form data (unsaved drafts and input fields)
   - All of the above, recommended

The rest: https://github.com/rshankras/claude-code-apple-skills/blob/HEAD/skills/generators/state-restoration/SKILL.md
