state-restoration

Generate SwiftUI state persistence infrastructure with Codable models and JSON auto-save.

27|5|Updated Apr 18, 2026
One-click install
npx skills add https://github.com/bocan/bocan-music --skill state-restoration-bocan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-restoration
Source: https://github.com/bocan/bocan-music/tree/main/.claude/skills/generators/state-restoration
Command: npx skills add https://github.com/bocan/bocan-music --skill state-restoration-bocan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the frustration of losing your place in a macOS or iOS app when it closes, terminates in the background, or relaunches, removing the need to manually re-navigate, re-scroll, or re-enter unsaved form data.

Core Features & Use Cases

  • Full UI State Persistence: Generates infrastructure to save and restore navigation paths, selected tabs, scroll positions, and unsaved form drafts.
  • Flexible Storage Options: Supports lightweight @SceneStorage/@AppStorage for simple state and file-based JSON persistence for complex state like navigation stacks.
  • Use Case: For a native macOS music player, this Skill can restore a user's last viewed library tab, scroll position in their song list, and unsaved playlist edit drafts the next time they open the app.

Quick Start

Use the state-restoration skill to generate production-ready state persistence code for your Swift app's navigation, tab, scroll, and form state.

Frequently Asked Questions about state-restoration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I save and restore SwiftUI navigation state across app launches?

To save and restore SwiftUI navigation state, use @SceneStorage for simple values or file-based JSON persistence for complex navigation stacks. This ensures navigation paths and tab selections are retained across app launches and background terminations.

What is the best way to persist unsaved form data in a Swift iOS app?

The best way to persist unsaved form data is by using Codable state models with debounced auto-save logic. This infrastructure automatically saves form drafts to file-based JSON storage before the app is terminated in the background.

Does state restoration work with both macOS and iOS native apps?

Yes, state restoration works with native macOS and iOS apps. It integrates @SceneStorage and @AppStorage to retain UI state across sessions on both platforms, handling background termination and relaunches.

How do I recover a scroll position after an app terminates in the background?

To recover scroll position after background termination, use @Observable state managers to capture scroll metrics and save them via debounced JSON persistence. The app restores these metrics using configurable time-limited restore logic upon relaunch.

When should I use @SceneStorage versus file-based JSON persistence for UI state?

Use @SceneStorage for lightweight UI state like simple tab selections, and file-based JSON persistence for complex state like deep navigation stacks or unsaved form input data. This combination ensures robust restoration without data size limitations.