comeonoliver/skillshub/axiom-swiftdata
Claude Code and agent skill by comeonoliver/skillshub
- community
- ext:[{"type":"config","description":"Configuration overrides"}]
Checking that the SKILL.md file is still in the repository.
Use when working with SwiftData - @Model definitions, @Query in SwiftUI, @Relationship macros, ModelContext patterns, CloudKit integration, iOS 26+ features, and Swift 6 concurrency with @MainActor — Apple's native persistence framework
Install
npx vskill@latest install comeonoliver/skillshub/axiom-swiftdataSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as comeonoliver/skillshub/axiom-swiftdata.
SwiftData
Overview
Apple's native persistence framework using @Model classes and declarative queries. Built on Core Data, designed for SwiftUI.
Core principle Reference types (class) + @Model macro + declarative @Query for reactive SwiftUI integration.
Requires iOS 17+, Swift 5.9+ Target iOS 26+ (this skill focuses on latest features) License Proprietary (Apple)
When to Use SwiftData
Choose SwiftData when you need
- ✅ Native Apple integration with SwiftUI
- ✅ Simple CRUD operations
- ✅ Automatic UI updates with
@Query - ✅ CloudKit sync (iOS 17+)
- ✅ Reference types (classes) with relationships
Use SQLiteData instead when
- Need value types (structs)
- CloudKit record sharing (not just sync)
- Large datasets (50k+ records) with specific performance needs
Use GRDB when
- Complex raw SQL required
- Fine-grained migration control needed
For migrations See the axiom-swiftdata-migration skill for custom schema migrations with VersionedSchema and SchemaMigrationPlan. For migration debugging, see axiom-swiftdata-migration-diag.
Example Prompts
These are real questions developers ask that this skill is designed to answer:
Basic Operations
1. "I have a notes app with folders. I need to filter notes by folder and sort by last modified. How do I set up the @Query?"
→ The skill shows how to use @Query with predicates, sorting, and automatic view updates
2. "When a user deletes a task list, all tasks should auto-delete too. How do I set up the relationship?"
→ The skill explains @Relationship with deleteRule: .cascade and inverse relationships
3. "I have a relationship between User → Messages → Attachments. How do I prevent orphaned data when deleting?"
→ The skill shows cascading deletes, inverse relationships, and safe deletion patterns
CloudKit & Sync
4. "My chat app syncs messages to other devices via CloudKit. Sometimes messages conflict. How do I handle sync conflicts?"
→ The skill covers CloudKit integration, conflict resolution strategies (last-write-wins, custom resolution), and sync patterns
5. "I'm adding CloudKit sync to my app, but I get 'Property must have a default value' error. What's wrong?"
→ The skill explains CloudKit constraints: all properties must be optional or have defaults, explains why (network timing), and shows fixes
6. "I want to show users when their data is syncing to iCloud and what happens when they're offline."
→ The skill shows monitoring sync status with notifications, detecting network connectivity, and offline-aware UI patterns
7. "I need to share a playlist with other users. How do I implement CloudKit record sharing?"
→ The skill covers CloudKit record sharing patterns (iOS 26+) with owner/permission tracking and sharing metadata
Performance & Optimization
8. "I need to query 50,000 messages but only display 20 at a time. How do I paginate efficiently?"
→ The skill covers performance patterns, batch fetching, limiting queries, and preventing memory bloat with chunked imports
9. "My app loads 100 tasks with relationships, and displaying them is slow. I think it's N+1 queries."
→ The skill shows how to identify N+1 problems without prefetching, provides prefetching pattern, and shows 100x performance improvement
10. "I'm importing 1 million records from an API. What's the best way to batch them without running out of memory?"
→ The skill shows chunk-based importing with periodic saves, memory cleanup patterns, and batch operation optimization
11. "Which properties should I add indexes to? I'm worried about over-indexing slowing down writes."
→ The skill explains index optimization patterns: when to index (frequently filtered/sorted properties), when to avoid (rarely used, frequently changing), maintenance costs
Migration from Legacy Frameworks
12. "We're migrating from Realm/Core Data to SwiftData"
→ See the comparison table in Migration section below, then follow realm-to-swiftdata-migration or axiom-swiftdata-migration for detailed guides
@Model Definitions
Basic Model
Key patterns
- Use
final class, notstruct(omitfinalif you need subclasses — see Class Inheritance below) - Use
@Attribute(.unique)for primary key-like behavior - Provide explicit
init(SwiftData doesn't synthesize) - Optional properties (
String?) are nullable - Use
@Attribute(.preserveValueOnDeletion)on properties whose values should survive even after the object is deleted (useful for analytics, audit trails)
Relationships
Many-to-Many Self-Referential Relationships
CRITICAL: SwiftData automatically manages BOTH sides when you modify ONE side.
✅ Correct — Only modify ONE side
❌ Wrong — Don't manually update both sides
Unfollowing (remove from ONE side only)
Verifying relationship integrity (for debugging)
CloudKit Sync Recovery (if relationships become corrupted)
Delete rules
.cascade- Delete related objects.nullify- Set relationship to nil.deny- Prevent deletion if relationship exists.noAction- Leave relationship as-is (careful!)
Class Inheritance
SwiftData supports class inheritance for hierarchical models. Use when you have a clear IS-A relationship (e.g., BusinessTrip IS-A Trip) and need both broad queries (all trips) and type-specific queries.
Base and Subclass Pattern
Apply @Model to both base class and subclasses. Omit final on the base class.
Type-Based Queries with #Predicate
Query all base class instances (includes subclasses), or filter by type:
Polymorphic Relationships
Relationships typed to the base class can hold mixed subclass instances:
Cast to access subclass-specific properties:
When to Use Inheritance vs Alternatives
| Signal | Use Inheritance | Use Enum/Flag Instead | |
|---|---|---|---|
| Subclasses share many base properties | Yes | — | |
| Need type-based queries across all models | Yes | — | |
| Subclasses have their own relationships | Yes | — | |
| Only 1-2 distinguishing properties | — | Yes | |
| Query only on specialized properties | — | Yes | |
| Protocol conformance suffices | — | Yes |
Keep hierarchies shallow (1-2 levels). Deep chains complicate schema migrations and queries.
ModelContainer Setup
SwiftUI App
Custom Configuration
In-Memory (Tests)
Queries in SwiftUI
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/CharlesWiltgen/Axiom/axiom-swiftdata/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Extension points
configConfiguration overrides
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/comeonoliver/skillshub/axiom-swiftdata)