{"enrichment":{"faq":[{"a":"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.","q":"How do you build a modular MVVM-C data layer with SwiftData?"},{"a":"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.","q":"What is SwiftData stale-while-revalidate and how do you implement it?"},{"a":"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.","q":"How does SwiftData handle optimistic writes and queued operations?"},{"a":"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.","q":"What are best practices for SwiftData schema migration and relationships?"},{"a":"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.","q":"How do you set up SwiftData ModelContainer and error recovery?"},{"a":"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.","q":"How does SwiftData support offline-first persistence and sync?"}],"shadow_tags":["data-layer-architecture","offline-first-sync","entity-relationship-modeling","schema-evolution","conflict-resolution","optimistic-updates","background-persistence","type-safe-queries","dependency-injection-patterns","preview-infrastructure"],"summary_rewrite":"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."},"files":[{"bytes":14039,"path":"skills/.experimental/swift-data/SKILL.md","sha256":"134a5c335934a05250a5a95a6212645aea36dd82552f2e5702b4e133b6887365","url":"https://skillfed.io/files/pproenca/dot-skills/swift-data/2fde56a2/SKILL.md"}],"id":"pproenca/dot-skills/swift-data","links":{"html":"https://skillfed.io/pproenca/dot-skills/swift-data","md":"https://skillfed.io/pproenca/dot-skills/swift-data.md","repo":"https://github.com/pproenca/dot-skills"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":14,"language":"Shell","last_updated":"2026-07-24","license":"MIT","name":"swift-data","publisher":"pproenca","stars":182},"relations":{"similar":[{"id":"pproenca/dot-skills/swift-ui-architect"},{"id":"pproenca/dot-skills/swift-refactor"},{"id":"pproenca/dot-skills/ios-xcode"},{"id":"pproenca/dot-skills/ios-testing"},{"id":"pproenca/dot-skills/ios-navigation"},{"id":"pproenca/dot-skills/ios-chaos-monkey"},{"id":"pproenca/dot-skills/ios-design-system"},{"id":"pproenca/dot-skills/ios-animations"},{"id":"rshankras/claude-code-apple-skills/integration-test-scaffold"},{"id":"pproenca/dot-skills/swift-optimise"}]},"slug":{"owner":"pproenca","repo":"dot-skills","skill":"swift-data"},"version":"2fde56a2"}
