AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Swiftdata Pro

skill-laxrajpurohit-swift-skills-pro-swiftdata-pro · by laxrajpurohit

Use when modeling data with SwiftData (@Model), writing @Query, configuring ModelContainer, performing migrations, or enabling CloudKit sync on iOS 17+.

No reviews yet
0 installs
13 views
0.0% view→install

Install

$ agentstack add skill-laxrajpurohit-swift-skills-pro-swiftdata-pro

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-laxrajpurohit-swift-skills-pro-swiftdata-pro)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
2mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Swiftdata Pro? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

SwiftData Pro

Model, query, and persist data with SwiftData correctly and efficiently.

When to use

  • Defining @Model types and relationships.
  • Writing @Query / fetching in views.
  • Setting up ModelContainer, migrations, or CloudKit sync.

Trigger: /swiftdata-pro.

Core principles

  • @Model classes are reference types managed by a ModelContext.
  • Inject the container at the app root with .modelContainer(for:).
  • Read in views with @Query; write through the modelContext.
  • Keep the main-actor context for UI; use a background ModelContext for bulk work.

Modeling

@Model
final class Trip {
    var name: String
    var startDate: Date
    @Relationship(deleteRule: .cascade) var stops: [Stop] = []

    init(name: String, startDate: Date) {
        self.name = name
        self.startDate = startDate
    }
}
  • Set an explicit deleteRule on relationships — don't rely on defaults for ownership.
  • Use @Attribute(.unique) for natural keys.
  • Mark large blobs @Attribute(.externalStorage).

❌ No delete rule on an owning relationship

var stops: [Stop] = []   // orphans Stop rows when a Trip is deleted

@Relationship(deleteRule: .cascade) var stops: [Stop] = []

Container setup

@main
struct TripsApp: App {
    var body: some Scene {
        WindowGroup { ContentView() }
            .modelContainer(for: Trip.self)
    }
}

Querying

Use @Query with sort/filter in the view; don't fetch-all then filter in Swift.

@Query private var trips: [Trip]
var upcoming: [Trip] { trips.filter { $0.startDate > .now } }   // loads everything

@Query(filter: #Predicate { $0.startDate > Date.now },
       sort: \Trip.startDate)
private var upcoming: [Trip]

Writing

@Environment(\.modelContext) private var context

func add(_ trip: Trip) {
    context.insert(trip)
    // SwiftData autosaves; call try? context.save() only when you need it now.
}

Delete with context.delete(trip).

Background work

For imports/bulk writes, use a separate context off the main actor and save in batches:

let context = ModelContext(container)
for row in rows { context.insert(Item(row)) }
try context.save()

Don't do thousands of inserts on the main-actor context — it blocks the UI.

Migrations

  • Lightweight changes (adding optional properties) migrate automatically.
  • Breaking changes need a SchemaMigrationPlan with versioned schemas and migration

stages. Define VersionedSchema types; never silently mutate a shipped model.

CloudKit sync

  • Every property must be optional or have a default; relationships must be optional.
  • No @Attribute(.unique) (CloudKit can't enforce it).
  • Configure with a ModelConfiguration using a CloudKit container identifier.

❌ (breaks CloudKit)

@Attribute(.unique) var code: String

var code: String = ""

Common mistakes checklist

  • [ ] Missing deleteRule on owning relationships.
  • [ ] Filtering fetched arrays in Swift instead of #Predicate in @Query.
  • [ ] Bulk inserts on the main-actor context.
  • [ ] .unique or non-optional properties on a CloudKit-synced model.
  • [ ] Breaking schema change with no migration plan.

Output format (when reviewing)

Per issue: file:line, rule, before/after. Lead with data-loss / migration risks.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.