guide-swiftdata

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Guide Skill — This is an expert workflow/pattern guide, not API reference documentation. Originally from twostraws/SwiftData-Agent-Skill by Paul Hudson. MIT License.
指南技能 — 这是一份专家级工作流/模式指南,而非API参考文档。 最初由Paul Hudson发布于twostraws/SwiftData-Agent-Skill,采用MIT许可证。

SwiftData Patterns

SwiftData 模式

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.
编写和审查SwiftData代码时,确保代码正确、使用现代API并遵循项目约定。仅报告真实存在的问题——不要吹毛求疵或编造问题。

Core Instructions

核心指导原则

  • Target Swift 6.2 or later, using modern Swift concurrency.
  • Prefer SwiftData across the board. Do not suggest Core Data unless the feature cannot be solved with SwiftData.
  • Do not introduce third-party frameworks without asking first.
  • 目标为Swift 6.2或更高版本,使用现代Swift并发机制。
  • 全面优先使用SwiftData。除非某个功能无法通过SwiftData实现,否则不要建议使用Core Data。
  • 未经询问,不要引入第三方框架。

Review Process

审查流程

  1. Check for core SwiftData issues using
    references/core-rules.md
    .
  2. Check that predicates are safe and supported using
    references/predicates.md
    .
  3. If the project uses CloudKit, check for CloudKit-specific constraints using
    references/cloudkit.md
    .
  4. If the project targets iOS 18+, check for indexing opportunities using
    references/indexing.md
    .
  5. 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.
  1. 使用
    references/core-rules.md
    检查核心SwiftData问题。
  2. 使用
    references/predicates.md
    检查谓词是否安全且受支持。
  3. 如果项目使用CloudKit,使用
    references/cloudkit.md
    检查CloudKit特定约束。
  4. 如果项目目标为iOS 18+,使用
    references/indexing.md
    检查索引优化机会。
  5. 如果项目目标为iOS 26+,使用
    references/class-inheritance.md
    检查类继承模式。
如果仅处理部分工作,只需加载相关的参考文件。

References

参考资料

TopicReference
Autosave, relationships, delete rules,
@Query
restrictions,
#Unique
,
@Transient
references/core-rules.md
Supported predicates, dangerous patterns that crash at runtime, unsupported methods
references/predicates.md
CloudKit constraints: no
#Unique
, optional requirements, eventual consistency
references/cloudkit.md
Database indexing (iOS 18+), single and compound property indexes
references/indexing.md
Model subclassing (iOS 26+),
@available
requirements, predicate filtering
references/class-inheritance.md
主题参考文件
自动保存、关联关系、删除规则、
@Query
限制、
#Unique
@Transient
references/core-rules.md
受支持的谓词、运行时会崩溃的危险模式、不受支持的方法
references/predicates.md
CloudKit约束:不支持
#Unique
、可选要求、最终一致性
references/cloudkit.md
数据库索引(iOS 18+)、单一属性索引与复合属性索引
references/indexing.md
模型子类化(iOS 26+)、
@available
要求、谓词过滤
references/class-inheritance.md