swiftdata-pro
twostraws/swiftdata-agent-skill
Write, review, and improve SwiftData code using modern APIs and best practices.
What is swiftdata-pro?
SwiftData-pro helps you write correct, performant SwiftData code by reviewing for core API issues, predicate safety, CloudKit constraints, and iOS 18+ indexing opportunities. Use it when reading, writing, or reviewing projects that use SwiftData.
- Reviews SwiftData code against core rules (autosaving, relationships, delete rules, property restrictions)
- Validates predicates for safety and runtime crash prevention
- Checks CloudKit-specific constraints (uniqueness, optionality, eventual consistency)
- Identifies indexing opportunities for iOS 18+ targets
- Validates class inheritance patterns for iOS 26+
How to install swiftdata-pro
npx skills add https://github.com/twostraws/swiftdata-agent-skill --skill swiftdata-proHow to use swiftdata-pro
- 1.Install the skill using: npx skills add https://github.com/twostraws/swiftdata-agent-skill --skill swiftdata-pro
- 2.Provide SwiftData code files or ask for a review of existing code
- 3.The skill will check against relevant reference rules based on your project context
- 4.Review the organized findings by file with before/after code fixes, or accept direct improvements to your code
Use cases
- Review a SwiftData model file for missing delete rules and relationship configurations
- Validate predicates in a query to prevent runtime crashes
- Check a CloudKit-synced SwiftData project for constraint violations
- Optimize database queries with indexes for iOS 18+ apps
- Write new SwiftData code following modern API patterns and project conventions
- iOS/macOS developers using SwiftData
- Teams migrating from Core Data to SwiftData
- Developers building CloudKit-synced apps with SwiftData
- Swift 6.2+ projects using modern concurrency
swiftdata-pro FAQ
Swift 6.2 or later, using modern Swift concurrency patterns.
No. The skill strongly prefers SwiftData across the board and will only suggest Core Data if a feature cannot be solved with SwiftData.
The skill will not introduce third-party frameworks without asking first.
The skill automatically checks CloudKit-specific constraints including uniqueness, optionality, and eventual consistency rules.
Yes. If your project targets iOS 18 or later, the skill identifies indexing opportunities for single and compound properties.
Full instructions (SKILL.md)
Source of truth, from twostraws/swiftdata-agent-skill.
name: swiftdata-pro description: Writes, reviews, and improves SwiftData code using modern APIs and best practices. Use when reading, writing, or reviewing projects that use SwiftData. license: MIT metadata: author: Paul Hudson version: "1.0"
Write and review SwiftData code for correctness, modern API usage, and adherence to project conventions. Report only genuine problems - do not nitpick or invent issues.
Review process:
- Check for core SwiftData issues using
references/core-rules.md. - Check that predicates are safe and supported using
references/predicates.md. - If the project uses CloudKit, check for CloudKit-specific constraints using
references/cloudkit.md. - If the project targets iOS 18+, check for indexing opportunities using
references/indexing.md. - If the project targets iOS 26+, check for class inheritance patterns using
references/class-inheritance.md.
If doing partial work, load only the relevant reference files.
Core Instructions
- Target Swift 6.2 or later, using modern Swift concurrency.
- The user strongly prefers to use SwiftData across the board. Do not suggest Core Data functionality unless it is a feature that cannot be solved with SwiftData.
- Do not introduce third-party frameworks without asking first.
- Use a consistent project structure, with folder layout determined by app features.
Output Format
If the user asks for a review, organize findings by file. For each issue:
- State the file and relevant line(s).
- Name the rule being violated.
- Show a brief before/after code fix.
Skip files with no issues. End with a prioritized summary of the most impactful changes to make first.
If the user asks you to write or improve code, follow the same rules above but make the changes directly instead of returning a findings report.
Example output:
Destination.swift
Line 8: Add an explicit delete rule for relationships.
// Before
var sights: [Sight]
// After
@Relationship(deleteRule: .cascade, inverse: \Sight.destination) var sights: [Sight]
Line 22: Do not use isEmpty == false in predicates – it crashes at runtime. Use ! instead.
// Before
#Predicate<Destination> { $0.sights.isEmpty == false }
// After
#Predicate<Destination> { !$0.sights.isEmpty }
DestinationListView.swift
Line 5: @Query must only be used inside SwiftUI views.
// Before
class DestinationStore {
@Query var destinations: [Destination]
}
// After
class DestinationStore {
var modelContext: ModelContext
func fetchDestinations() throws -> [Destination] {
try modelContext.fetch(FetchDescriptor<Destination>())
}
}
Summary
- Data loss (high): Missing delete rule on line 8 of Destination.swift means sights will be orphaned when a destination is deleted.
- Crash (high):
isEmpty == falseon line 22 will crash at runtime – use!isEmptyinstead. - Incorrect behavior (high):
@Queryon line 5 of DestinationListView.swift only works inside SwiftUI views.
End of example.
References
references/core-rules.md- autosaving, relationships, delete rules, property restrictions, and FetchDescriptor optimization.references/predicates.md- supported predicate operations, dangerous patterns that crash at runtime, and unsupported methods.references/cloudkit.md- CloudKit-specific constraints including uniqueness, optionality, and eventual consistency.references/indexing.md- database indexing for iOS 18+, including single and compound property indexes.references/class-inheritance.md- model subclassing for iOS 26+, including @available requirements, schema setup, and predicate filtering.
Related skills
More from twostraws/swiftdata-agent-skill and the wider catalog.
find-skills
Discover and install agent skills to extend your coding agent's capabilities on demand
frontend-design
Build visually distinctive UI with opinionated aesthetic direction, typography, and layout choices that avoid templated defaults.
vercel-react-best-practices
70 React/Next.js performance rules from Vercel Engineering, prioritized by impact for writing, reviewing, and refactoring code.
agent-browser
Fast browser automation CLI for AI agents — navigate, click, scrape, screenshot, and test via Chrome CDP
web-design-guidelines
Review UI code against Web Interface Guidelines for accessibility, UX, and design best practices
finetuning
Fine-tune models on Azure AI Foundry with SFT, DPO, or RFT training methods.