본문으로 건너뛰기
cccskills
무료GitHub에 공개

swiftdata-expert-skill

Expert guidance for designing, implementing, migrating, and debugging SwiftData persistence in Swift and SwiftUI apps. Use when working with @Model schemas, @Relationship/@Attribute rules, Query or FetchDescriptor data access, ModelContainer/ModelContext configuration, CloudKit sync, SchemaMigrationPlan/history APIs, ModelActor concurrency isolation, or Core Data to SwiftData adoption/coexistence.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(11)

  • SKILL.md9.1 KB
  • references/cloudkit-sync.md2.0 KB
  • references/concurrency-and-actors.md1.6 KB
  • references/core-data-adoption.md1.6 KB
  • references/implementation-playbooks.md2.6 KB
  • references/migrations-and-history.md2.2 KB
  • references/model-context-and-lifecycle.md2.5 KB
  • references/modeling-and-schema.md3.0 KB
  • references/querying-and-fetching.md2.2 KB
  • references/relationships-and-inheritance.md2.1 KB
  • references/troubleshooting-and-updates.md1.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

SwiftData Expert Skill

Overview

Use this skill to build, review, and harden SwiftData persistence architecture with Apple-documented patterns from iOS 17 through current updates. Prioritize data integrity, migration safety, sync correctness, and predictable concurrency behavior.

Agent Behavior Contract (Follow These Rules)

  1. Identify the minimum deployment target before recommending APIs (notably #Index, #Unique, HistoryDescriptor, DataStore, inheritance examples).
  2. Confirm the app has real ModelContainer wiring before debugging data issues; without it, inserts fail and fetches are empty.
  3. Distinguish main-actor UI operations from background persistence operations; never assume one context fits both.
  4. Treat schema changes as migration changes: evaluate lightweight migration first, then SchemaMigrationPlan when needed.
  5. For CloudKit-enabled apps, verify schema compatibility constraints before proposing model changes.
  6. Prefer deterministic query definitions (shared predicates, explicit sort order, bounded fetches) over ad hoc filtering in views.
  7. Use persistent history tokens when reading cross-process changes; delete stale history to avoid storage growth.
  8. In code reviews, prioritize data loss risk, accidental mass deletion, sync divergence, and context-isolation bugs over style changes.

Analysis Commands (Use Early)

  • Search container setup:
    • rg "modelContainer\\(|ModelContainer\\(" -n
  • Search model definitions:
    • rg "^@Model|#Unique|#Index|@Relationship|@Attribute|@Transient" -n
  • Search context usage:
    • rg "modelContext|mainContext|ModelContext\\(" -n
  • Search migrations and history:
    • rg "SchemaMigrationPlan|VersionedSchema|MigrationStage|fetchHistory|deleteHistory|historyToken" -n
  • Search CloudKit and app groups:
    • rg "cloudKitDatabase|iCloud|CloudKit|groupContainer|AppGroup|NSPersistentCloudKitContainer" -n

Project Intake (Before Advising)

  • Determine deployment targets: iOS, iPadOS, macOS, watchOS, and visionOS.
  • Locate container setup: .modelContainer(...) modifier or manual ModelContainer(...).
  • Verify whether autosave is expected and whether explicit save() is required.
  • Check if undo is enabled (isUndoEnabled) and whether operations occur on mainContext or custom contexts.
  • Check CloudKit capabilities and chosen container strategy (automatic, .private(...), .none).
  • Check if app group storage is required.
  • Check if Core Data coexistence is in scope.
  • Check if schema changes must be backward-compatible with existing user data.

Workflow Decision Tree

  1. Need a new model or schema shape:
    • Read references/modeling-and-schema.md.
  2. Need create, update, delete behavior or context correctness:
    • Read references/model-context-and-lifecycle.md.
  3. Need filtering, sorting, or dynamic list behavior:
    • Read references/querying-and-fetching.md.
  4. Need relationship modeling or inheritance:
    • Read references/relationships-and-inheritance.md.
  5. Need migration planning, release upgrades, or change tracking:
    • Read references/migrations-and-history.md.
  6. Need iCloud sync or CloudKit compatibility:
    • Read references/cloudkit-sync.md.
  7. Need incremental migration from Core Data:
    • Read references/core-data-adoption.md.
  8. Need background isolation or actor-based persistence:
    • Read references/concurrency-and-actors.md.
  9. Need quick diagnostics or API availability checks:
    • Read references/troubleshooting-and-updates.md.
  10. Need end-to-end execution playbook for a concrete task:
  • Read references/implementation-playbooks.md.

Triage-First Playbook (Common Problems -> Next Move)

  • Insert fails or fetch is always empty:
    • Confirm .modelContainer(...) is attached at app or window root and the model type is included.
  • Duplicate rows appear after network refresh:
    • Add @Attribute(.unique) or #Unique constraints and rely on insert-upsert behavior.
  • Unexpected data loss during delete:
    • Audit delete rules (.cascade vs .nullify) and check for unbounded delete(model:where:).
  • Undo or redo does nothing:
    • Ensure isUndoEnabled: true and that changes are saved via mainContext (not only background context).
  • CloudKit sync not behaving:
    • Check capabilities, remote notifications, and CloudKit schema compatibility; explicitly set cloudKitDatabase if multiple containers exist.
  • Widget or App Intent changes are not reflected:
    • Use persistent history (fetchHistory) with token + author filtering.
  • historyTokenExpired appears:
    • Reset local token strategy and rebootstrap change consumption from a safe point.
  • Query results are expensive or unstable:
    • Use shared predicate builders, explicit sorting, and bounded FetchDescriptor settings.

Anti-Patterns (Reject by Default)

  • Building persistence logic before validating container wiring.
  • Performing broad deletes without predicate review and confirmation.
  • Mixing UI-driven editing and background write pipelines without isolation boundaries.
  • Relying on ad hoc in-memory filtering instead of store-backed predicates.
  • Enabling CloudKit sync without capability setup and schema compatibility checks.
  • Shipping schema changes without migration rehearsal on existing user data.
  • Consuming history without token persistence and cleanup policy.

Core Patterns

App-level container wiring (SwiftUI)

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            RootView()
        }
        .modelContainer(for: [Trip.self, Accommodation.self])
    }
}

Manual container configuration

let config = ModelConfiguration(isStoredInMemoryOnly: false)
let container = try ModelContainer(
    for: Trip.self,
    Accommodation.self,
    configurations: config
)

Dynamic query setup in a view initializer

struct TripListView: View {
    @Query private var trips: [Trip]

    init(searchText: String) {
        let predicate = #Predicate<Trip> {
            searchText.isEmpty || $0.name.localizedStandardContains(searchText)
        }
        _trips = Query(filter: predicate, sort: \.startDate, order: .forward)
    }

    var body: some View { List(trips) { Text($0.name) } }
}

Safe batch delete pattern

do {
    try modelContext.delete(
        model: Trip.self,
        where: #Predicate { $0.endDate < .now },
        includeSubclasses: true
    )
    try modelContext.save()
} catch {
    // Handle delete and save failures.
}

Reference Files

  • references/modeling-and-schema.md
  • references/model-context-and-lifecycle.md
  • references/querying-and-fetching.md
  • references/relationships-and-inheritance.md
  • references/migrations-and-history.md
  • references/cloudkit-sync.md
  • references/core-data-adoption.md
  • references/concurrency-and-actors.md
  • references/troubleshooting-and-updates.md
  • references/implementation-playbooks.md

Best Practices Summary

  1. Keep model code as the source of truth; avoid hidden schema assumptions.
  2. Apply explicit uniqueness and indexing strategy for large or frequently queried datasets.
  3. Insert root models and let SwiftData traverse relationship graphs automatically.
  4. Keep query behavior deterministic with explicit predicates and sort descriptors.
  5. Bound fetches (fetchLimit, offsets, identifier-only fetches) for scalability.
  6. Treat delete rules as business rules; review them during schema changes.
  7. Use ModelConfiguration for environment-specific behavior (in-memory tests, CloudKit, app groups, read-only stores).
  8. Handle history as an operational system: token persistence, filtering, and cleanup.
  9. Use model actors or isolated contexts for non-UI persistence work.
  10. Gate recommendations by API availability and deployment target.

Verification Checklist (After Changes)

  • Build succeeds for target platforms and minimum deployment versions.
  • CRUD tests pass with real store and in-memory store.
  • Relationship deletes behave as intended (cascade, nullify, and others).
  • Query behavior is stable with realistic datasets and sort or filter combinations.
  • Migration path is validated on pre-existing data (not only clean installs).
  • CloudKit behavior is validated in a development container before release.
  • Cross-process changes (widgets, intents, extensions) are observed correctly.
  • Error paths and rollback behavior are covered for destructive operations.

Response Contract

  • For review tasks, report findings first by severity and include exact file paths and lines.
  • For implementation tasks, describe:
    • container or context changes,
    • schema or migration changes,
    • query or performance changes,
    • verification steps run and any gaps.
  • If deployment target blocks a recommended API, provide the best fallback compatible with the current target.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

When the user wants to A/B test App Store product page elements to improve conversion rate. Also use when the user mentions "A/B test", "product page optimization", "test my screenshots", "test my icon", "conversion rate optimization", "CPP", or "custom product pages". For screenshot design, see screenshot-optimization. For metadata optimization, see metadata-optimization.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

JordanCoin/ios-skills-collection62026년 9월 10일 업데이트

Discover and configure Bluetooth and Wi-Fi accessories using AccessorySetupKit. Use when presenting a privacy-preserving accessory picker, defining discovery descriptors for BLE or Wi-Fi devices, handling accessory session events, migrating from CoreBluetooth permission-based scanning, or setting up accessories without requiring broad Bluetooth permissions.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

JordanCoin/ios-skills-collection62026년 9월 10일 업데이트

Implement, review, or improve Live Activities and Dynamic Island experiences in iOS apps using ActivityKit. Use when building real-time updating widgets for the Lock Screen and Dynamic Island — delivery tracking, sports scores, ride-sharing status, workout timers, media playback, or any time-sensitive information that updates in real time. Also use when working with ActivityKit, ActivityAttributes, Activity lifecycle (request/update/end), Dynamic Island layouts (compact/minimal/expanded), push-to-update Live Activities, or Lock Screen live widgets.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

JordanCoin/ios-skills-collection62026년 9월 10일 업데이트

Measure ad effectiveness with privacy-preserving attribution using AdAttributionKit. Use when registering ad impressions, handling attribution postbacks, updating conversion values, implementing re-engagement attribution, configuring publisher or advertiser apps, or replacing SKAdNetwork with AdAttributionKit for ad measurement.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

JordanCoin/ios-skills-collection62026년 9월 10일 업데이트

alarmkit

무료

Implement AlarmKit alarms and countdown timers for iOS and iPadOS with Lock Screen, Dynamic Island, and Apple Watch system UI. Covers AlarmManager scheduling, AlarmAttributes and AlarmPresentation, AlarmButton stop and snooze actions, authorization, state observation, and Live Activity integration. Use when building wake-up alarms, countdown timers, or alarm-style alerts that need Apple's system alarm experience.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

JordanCoin/ios-skills-collection62026년 9월 10일 업데이트

When the user wants to optimize their Google Play Store listing — title, short description, full description, keywords, ratings, or Play Store-specific features. Use when the user mentions "Google Play", "Android", "Play Store", "Play Console", "short description", "full description indexed", "Google Play ASO", or wants Google Play-specific keyword, creative, or ratings strategy. For iOS App Store optimization, see aso-audit and metadata-optimization.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

JordanCoin/ios-skills-collection62026년 9월 10일 업데이트

JordanCoin의 스킬 모두 보기

이 스킬의 문제 신고