swift-data
This skill equips AI agents with the knowledge to architect scalable data persistence solutions in Swift using SwiftData's modern ORM capabilities. It covers entity modeling, repository patterns, and clean architecture principles tailored for MVVM-C workflows. Developers gain practical guidance on structuring data layers that remain maintainable as iOS projects grow in complexity.
swift-data enables modular MVVM-C architectures by separating concerns into distinct layers. Create a repository pattern that abstracts SwiftData's ModelContainer and @Query operations behind protocol-based interfaces. Define domain models independently from @Model entities, then map between them in a dedicated mapper layer. This isolation lets ViewModels depend only on repository protocols, not SwiftData directly, making testing and feature scaling straightforward.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-07-24
swift-data enables modular MVVM-C architectures by separating concerns into distinct layers. Create a repository pattern that abstracts SwiftData's ModelContainer and @Query operations behind protocol-based interfaces. Define domain models independently from @Model entities, then map between them in a dedicated mapper layer. This isolation lets ViewModels depend only on repository protocols, not SwiftData directly, making testing and feature scaling straightforward.
Use it when
- swift-data supports stale-while-revalidate reads by serving cached data immediately while fetching fresh results in the background.
- swift-data optimistic writes queue changes locally before server confirmation.
Verify before relying
Read SKILL.md below before installing (60 files). Open directory: indexed for reading, not audited.
Install
pproenca/dot-skills/swift-data · repository language: Shell
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do you build a modular MVVM-C data layer with SwiftData?
swift-data enables modular MVVM-C architectures by separating concerns into distinct layers. Create a repository pattern that abstracts SwiftData's ModelContainer and @Query operations behind protocol-based interfaces. Define domain models independently from @Model entities, then map between them in a dedicated mapper layer. This isolation lets ViewModels depend only on repository protocols, not SwiftData directly, making testing and feature scaling straightforward.
What is SwiftData stale-while-revalidate and how do you implement it?
swift-data supports stale-while-revalidate reads by serving cached data immediately while fetching fresh results in the background. Implement this by storing a timestamp with each entity, querying local data first with @Query, then triggering a background sync task that updates the ModelContainer when new data arrives. Use @ObservedReferenceable or manual refresh triggers to notify SwiftUI views of updates without blocking the initial render.
How does SwiftData handle optimistic writes and queued operations?
swift-data optimistic writes queue changes locally before server confirmation. Save mutations to the ModelContainer immediately, assign a pending state flag, and enqueue the write operation. If the network request succeeds, clear the flag; on failure, either retry automatically or present a conflict resolution UI. This pattern keeps the app responsive while maintaining eventual consistency with your backend.
What are best practices for SwiftData schema migration and relationships?
swift-data schema migrations use versioned ModelContainer configurations. Define one-to-many relationships with @Relationship(deleteRule: .cascade) to maintain referential integrity. Version your schema incrementally, providing migration logic in ModelConfiguration. For complex relationships, use lightweight migrations when possible. Test migrations on sample data before release to catch cascading delete issues and orphaned records early.
How do you set up SwiftData ModelContainer and error recovery?
swift-data ModelContainer initialization requires specifying your @Model types and a ModelConfiguration. Wrap container creation in try-catch to handle initialization failures gracefully. Implement error recovery by logging failures, offering users options to retry or clear local data, and maintaining a fallback in-memory store if persistence fails. Set up preview infrastructure with lightweight ModelContainers using inMemory storage for SwiftUI previews and tests.
How does SwiftData support offline-first persistence and sync?
swift-data enables offline-first architectures by persisting all writes locally first. Implement background sync tasks that queue pending changes, retry failed syncs with exponential backoff, and resolve conflicts when offline edits clash with server state. Use @Query to surface sync status in UI, letting users see which changes are pending. Combine with URLSession background tasks for reliable sync even when the app is backgrounded.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
SwiftData Best Practices — Modular MVVM-C Data Layer
Comprehensive data modeling, persistence, sync architecture, and error handling guide for SwiftData aligned with the clinic modular MVVM-C stack.
Architecture Alignment
This skill enforces the same modular architecture mandated by swift-ui-architect:
``` ┌───────────────────────────────────────────────────────────────┐ │ Feature modules: View + ViewModel, no SwiftData imports │ ├───────────────────────────────────────────────────────────────┤ │ Domain: models + repository/coordinator/error protocols │ ├───────────────────────────────────────────────────────────────┤ │ Data: @Model entities, SwiftData stores, repository impls, │ │ remote clients, retry executor, sync queue, conflict handling
(truncated - see the full file via the links below)
File tree — 15 files
skills/.experimental/swift-data/SKILL.md
skills/.experimental/swift-data/metadata.json
skills/.experimental/swift-data/references/_sections.md
skills/.experimental/swift-data/references/crud-cancel-delete.md
skills/.experimental/swift-data/references/crud-delete-indexset.md
skills/.experimental/swift-data/references/crud-dismiss-save.md
skills/.experimental/swift-data/references/crud-edit-button.md
skills/.experimental/swift-data/references/crud-insert-context.md
skills/.experimental/swift-data/references/crud-save-error-handling.md
skills/.experimental/swift-data/references/crud-sheet-creation.md
skills/.experimental/swift-data/references/crud-undo-cancel.md
skills/.experimental/swift-data/references/model-class-for-persistence.md
skills/.experimental/swift-data/references/model-computed-properties.md
skills/.experimental/swift-data/references/model-custom-types.md
skills/.experimental/swift-data/references/model-defaults.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Build a modular MVVM-C data layer with SwiftData entities and repositories”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
swift-ui-architect equips AI agents with the expertise to design and implement robust SwiftUI applications using proven architectural patterns. The skill enforces separation of concerns through MVVM-C layering, Swift Package Manager organization, and coordinator-based navigation, enabling agents to generate production-ready iOS codebases that scale with team complexity.
swift-refactor helps developers modernize SwiftUI applications by transforming existing code into clean, modular MVVM-C patterns. It leverages Swift's @Observable macro and SPM package boundaries to create maintainable, scalable architectures that separate concerns and improve testability.
This skill equips developers with structured testing methodologies tailored for iOS applications built on modular MVVM-C architecture. Explore practical approaches to unit testing, integration testing, and UI automation while maintaining clean separation of concerns across your codebase. Strengthen your testing foundation to build more reliable and maintainable iOS applications.
ios-xcode equips AI agents with specialized capabilities for iOS development workflows, enabling configuration of Xcode projects with SwiftData persistence layers and clinic-pattern MVVM-C architecture. This skill extends coding agents with domain knowledge for building structured, maintainable iOS applications.
This skill equips developers with Apple's Human Interface Guidelines, providing essential design principles and patterns for building polished SwiftUI applications. Access curated rules, accessibility requirements, and platform-specific best practices to ensure your iOS apps meet Apple's quality standards and deliver excellent user experiences.
This skill equips AI agents to work directly with iOS storyboard files, enabling updates and restructuring of interface layouts within healthcare applications. It integrates with the Agent Skills open format to provide domain-specific capabilities for managing UI components and screen configurations in clinic-focused iOS development.
More skills ios-chaos-monkey (MIT) · ios-design-system (MIT) · integration-test-scaffold (MIT) · Swiftdata (NOASSERTION) · axiom-audit-swiftdata (MIT) · swiftdata-expert-skill (MIT)