360 Secure SkillHub
360 安全技能中心

swiftdata

将 SwiftData 实现任务路由到对应知识契约:模型定义(@Model/@Attribute/@Relationship/@Transient)、ModelContainer/ModelConfiguration 配置注入、ModelContext 增删改查、@Query/FetchDescriptor 查询与删除规则;不含 CloudKit 同步、Schema 迁移与 Core Data …

caglarbaranbora
热度 0.00
最近更新 2026-10-18 16:48:09
分类:知识依赖:纯提示词应用场景:代码生成 / 概念解释 / 研究

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add caglarbaranbora/apple-agent-kit/swiftdata
Metadata
name
swiftdata
description
Route SwiftData implementation tasks to the correct Knowledge Contracts -- declaring persistent model classes with @Model/@Attribute/@Relationship/@Transient, creating and injecting a ModelContainer/ModelConfiguration via .modelContainer, ModelContext CRUD (insert/delete/save/autosave/undo), fetching with @Query or FetchDescriptor+context.fetch(_:), and @Relationship(deleteRule:) referential integrity. Use when writing @Model class RemoteImage { ... }, @Attribute(.unique), @Relationship(deleteRule:inverse:), @Transient, ModelContainer(for:configurations:), ModelConfiguration(isStoredInMemoryOnly:), .modelContainer(for:)/.modelContainer(_:), @Environment(\.modelContext), context.insert(_:)/delete(_:)/save(), context.autosaveEnabled, context.undoManager, @Query(filter:sort:order:),
id
skill.swiftdata.foundations
title
SwiftData — Foundations
version
1.0.0
status
Approved
artifact_type
skill
domain
SwiftData
routes
["knowledge.swiftdata.model-definition","knowledge.swiftdata.model-container-setup","knowledge.swiftdata.model-context-crud","knowledge.swiftdata.querying-with-query-and-fetchdescriptor","knowledge.swiftdata.relationships-and-cascade-delete"]
related
[]
last_updated
"2026-08-08T00:00:00.000Z"

SwiftData — Foundations Skill

Purpose

Route SwiftData implementation tasks to the minimum required SwiftData Knowledge Contracts. v1 scope is declaring @Model classes and their attributes/relationships, setting up and injecting a ModelContainer, performing CRUD through a ModelContext, fetching with @Query or FetchDescriptor, and delete-rule/referential-integrity behavior on relationships -- not CloudKit sync, not schema migration, not Core Data interop, and not the #Index/#Unique macros beyond a basic mention.

Routing

Load only the contracts relevant to the task. All paths relative to knowledge/swiftdata/.

  • Annotating a class with @Model; customizing a property with @Attribute (e.g. .unique) or @Transient; declaring a @Relationship property and its inverse:; or asking what SwiftData auto-synthesizes (Identifiable/Hashable/Observable, not Codable) -> model-definition.md
  • Setting up .modelContainer(for:)/.modelContainer(_:); configuring ModelConfiguration (isStoredInMemoryOnly, allowsSave); creating a ModelContainer(for:configurations:) manually for previews/tests/non-SwiftUI code; or wiring @Environment(\.modelContext) -> model-container-setup.md
  • Calling context.insert(_:)/delete(_:)/save(); deciding whether autosaveEnabled makes an explicit save() unnecessary; choosing mainContext vs. a manually created secondary ModelContext; or enabling undo via context.undoManager -> model-context-crud.md
  • Fetching with @Query (filter:/sort:/order:/animation:) in a SwiftUI view; building a #Predicate; or fetching outside a view with FetchDescriptor<Model> + context.fetch(_:) -> querying-with-query-and-fetchdescriptor.md
  • Choosing a @Relationship(deleteRule:) value (.cascade/.nullify/.deny/.noAction); reasoning about what happens to related models on delete; or diagnosing a one-directional relationship missing its inverse: -> relationships-and-cascade-delete.md

Never load more than the contracts relevant to the specific question.

Stop Conditions

Stop and report if the requested topic has no matching Knowledge Contract in knowledge/swiftdata/ — do not guess or fall back to general knowledge. CloudKit sync integration (ModelConfiguration(cloudKitDatabase:)) is out of scope entirely -- not built as a contract here. Schema migration (SchemaMigrationPlan, VersionedSchema, lightweight vs. custom migration) is out of scope entirely -- not yet built. Core Data interop or migration (NSManagedObjectContext, NSFetchRequest) belongs to a separate Core Data domain, not this one -- do not answer Core Data questions from SwiftData contracts or fabricate a shared API surface. The #Index/ #Unique freestanding macros beyond the basic @Attribute(.unique) case, and SwiftData in widget extensions or App Group container sharing, are out of scope entirely -- report the boundary rather than fabricate behavior.