swift-sharing

Manage and synchronize shared app state with automatic persistence.

16|2|Updated Jan 1, 2026
One-click install
npx skills add https://github.com/nonameplum/agent-skills --skill swift-sharing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-sharing
Source: https://github.com/nonameplum/agent-skills/tree/main/swift-sharing
Command: npx skills add https://github.com/nonameplum/agent-skills --skill swift-sharing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Swift-Sharing provides a unified approach to share mutable state across an app while ensuring changes persist and propagate to all dependents. It reduces boilerplate for coordinating state, persistence, and UI updates across modules.

Core Features & Use Cases

  • Shared state across features with automatic persistence to in-memory, appStorage, and fileStorage; suitable for configuration, preferences, and cross-feature data.
  • Live observation and propagation via SwiftUI and Combine so that views and models stay synchronized with the source of truth.
  • Safe mutation patterns with explicit locking and structured load/save lifecycles to avoid data races in concurrent environments.

Quick Start

  1. Add a Shared property to a model with a chosen storage key, e.g., Shared(.appStorage("count")) var count = 0.
  2. Access and mutate the shared value via the projected value to react to changes and persist updates.
  3. Run your app; changes are observed across features and persisted automatically.

Frequently Asked Questions about swift-sharing

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

FAQPage Schema
How do I share and persist app state across SwiftUI features?

You can share and persist app state by conforming types to SharedKey protocols, enabling automatic synchronization and throttled persistence across in-memory, user defaults, and file storage in SwiftUI.

What is the best way to synchronize mutable state across iOS app modules?

Synchronizing mutable state across modules requires explicit locking and structured load/save lifecycles to avoid data races, ensuring changes propagate deterministically to all dependent views and models.

Can I use Combine to observe shared state changes in Swift?

Combine supports live observation of shared state changes by subscribing to SharedReaderKey conforming types, allowing views and background tasks to react synchronously to persisted updates.

How do I persist user preferences to fileStorage and appStorage in SwiftUI?

Persist user preferences by declaring Shared properties with chosen storage keys like .appStorage or .fileStorage, which automatically handle loading and saving values across app sessions.

Does Swift-Sharing work with concurrent environments to prevent data races?

Swift-Sharing manages concurrent environments safely by applying explicit locking patterns during mutation and structured load/save lifecycles, preventing data races when accessing shared state.

Why do I need SharedReaderKey and SharedKey protocols for state persistence?

SharedReaderKey and SharedKey protocols are required to implement deterministic loading, subscription, and throttled saving mechanisms, establishing a unified source of truth for app state persistence.