swiftdata-code-review
Reviews SwiftData code for model design, queries, concurrency, and migrations. Use when reviewing .swift files with import SwiftData, @Model, @Query, @ModelActor, or VersionedSchema.
Files5
View on GitHubSKILL.mdskills/swiftdata-code-review/SKILL.md
GitHubSwiftData Code Review
Quick Reference
| Issue Type | Reference |
|---|---|
@Model, @Attribute, #Unique, @Relationship, delete rules |
references/model-design.md |
@Query, #Predicate, FetchDescriptor, #Index |
references/queries.md |
@ModelActor, ModelContext, background operations, DTOs |
references/concurrency.md |
VersionedSchema, MigrationStage, lightweight/custom |
references/migrations.md |
Hard gates (before reporting findings)
Run in order; do not assert an issue until the gate for that issue passes.
- Scope — pass when: You have the target
.swiftpath(s) and confirmed SwiftData surface in scope (e.g.import SwiftData,@Model,@Query,@ModelActor,VersionedSchema, or migration types). If none apply, stop or narrow scope with one sentence. - Reference — pass when: For each checklist area you evaluate (models, queries, concurrency, migrations), you opened the matching
references/*.mdfrom the Quick Reference table or wroteN/A: no <area> in this reviewwith a one-line reason. - Evidence & protocol — pass when: Every finding satisfies
review-verification-protocol(review-verification-protocol) and uses the[FILE:LINE] ISSUE_TITLEheader (line range allowed) from the file you read; no finding without a cite. - Report — pass when: Findings list cites first (or inline) using
[FILE:LINE] ISSUE_TITLE, then severity or checklist grouping—no uncited assertions.
Review Checklist
- Models marked
finalon iOS 17–18 (or when inheritance is not intended; iOS 26+ supports@Modelsubclassing) -
@Relationshipdecorator on ONE side only (not both) - Delete rules explicitly set (not relying on default
.nullify) - Relationships initialized to empty arrays (
= []), not default model objects - No
@Attribute(.unique)or#Unique(iOS 18+) if CloudKit sync is enabled - Batch operations used for bulk inserts (
append(contentsOf:)) -
@Querynot loading thousands of items on main thread - External values in predicates captured in local variables (including inside
init()) - Scalar comparisons in predicates (not object references)
-
@ModelActorused for background operations (created off@MainActor) -
PersistentIdentifierorSendableDTOs used to pass data between actors (never@Modelinstances) -
VersionedSchemadefined for each shipped version andMigrationPlanpassed toModelContainer
When to Load References
- Reviewing
@Model,#Unique, or relationships -> references/model-design.md - Reviewing
@Query,#Predicate, or#Index-> references/queries.md - Reviewing
@ModelActoror background work -> references/concurrency.md - Reviewing schema changes or migrations -> references/migrations.md
Review Questions
- Could this relationship assignment cause NULL foreign keys?
- Is
@Relationshipon both sides creating circular references? - Could this
@Queryblock the main thread with large datasets? - Are
@Modelobjects being passed across actor boundaries instead ofPersistentIdentifierorSendableDTOs? - Would schema changes require a
VersionedSchemaandSchemaMigrationPlan?