swiftdata-pro by twostraws/swiftdata-agent-skill
npx skills add https://github.com/twostraws/swiftdata-agent-skill --skill swiftdata-pro为 SwiftData 代码的正确性、现代 API 使用以及项目规范的遵循性进行编写和审查。仅报告真实存在的问题——不要吹毛求疵或捏造问题。
审查流程:
references/core-rules.md 检查核心 SwiftData 问题。references/predicates.md 检查谓词是否安全且受支持。references/cloudkit.md 检查 CloudKit 特定约束。references/indexing.md 检查索引优化机会。references/class-inheritance.md 检查类继承模式。如果进行部分工作,仅加载相关的参考文件。
如果用户要求审查,请按文件组织发现的问题。对于每个问题:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
跳过没有问题的文件。最后提供一个优先级的总结,列出应首先进行的最具影响力的更改。
如果用户要求你编写或改进代码,请遵循上述相同规则,但直接进行更改,而不是返回问题报告。
示例输出:
第 8 行:为关系添加显式的删除规则。
// 修复前
var sights: [Sight]
// 修复后
@Relationship(deleteRule: .cascade, inverse: \Sight.destination) var sights: [Sight]
第 22 行:不要在谓词中使用 isEmpty == false——这会在运行时崩溃。请改用 !。
// 修复前
#Predicate<Destination> { $0.sights.isEmpty == false }
// 修复后
#Predicate<Destination> { !$0.sights.isEmpty }
第 5 行:@Query 必须仅在 SwiftUI 视图中使用。
// 修复前
class DestinationStore {
@Query var destinations: [Destination]
}
// 修复后
class DestinationStore {
var modelContext: ModelContext
func fetchDestinations() throws -> [Destination] {
try modelContext.fetch(FetchDescriptor<Destination>())
}
}
isEmpty == false 会在运行时崩溃——请改用 !isEmpty。@Query 仅在 SwiftUI 视图中有效。示例结束。
references/core-rules.md - 自动保存、关系、删除规则、属性限制以及 FetchDescriptor 优化。references/predicates.md - 支持的谓词操作、会导致运行时崩溃的危险模式以及不支持的方法。references/cloudkit.md - CloudKit 特定约束,包括唯一性、可选性和最终一致性。references/indexing.md - iOS 18+ 的数据库索引,包括单属性和复合属性索引。references/class-inheritance.md - iOS 26+ 的模型子类化,包括 @available 要求、模式设置和谓词过滤。每周安装量
1.2K
代码仓库
GitHub 星标数
183
首次出现
14 天前
安全审计
安装于
codex1.2K
github-copilot1.2K
opencode1.2K
kimi-cli1.2K
gemini-cli1.2K
amp1.2K
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.
Review process:
references/core-rules.md.references/predicates.md.references/cloudkit.md.references/indexing.md.references/class-inheritance.md.If doing partial work, load only the relevant reference files.
If the user asks for a review, organize findings by file. For each issue:
Skip files with no issues. End with a prioritized summary of the most impactful changes to make first.
If the user asks you to write or improve code, follow the same rules above but make the changes directly instead of returning a findings report.
Example output:
Line 8: Add an explicit delete rule for relationships.
// Before
var sights: [Sight]
// After
@Relationship(deleteRule: .cascade, inverse: \Sight.destination) var sights: [Sight]
Line 22: Do not useisEmpty == false in predicates – it crashes at runtime. Use ! instead.
// Before
#Predicate<Destination> { $0.sights.isEmpty == false }
// After
#Predicate<Destination> { !$0.sights.isEmpty }
Line 5:@Query must only be used inside SwiftUI views.
// Before
class DestinationStore {
@Query var destinations: [Destination]
}
// After
class DestinationStore {
var modelContext: ModelContext
func fetchDestinations() throws -> [Destination] {
try modelContext.fetch(FetchDescriptor<Destination>())
}
}
isEmpty == false on line 22 will crash at runtime – use !isEmpty instead.@Query on line 5 of DestinationListView.swift only works inside SwiftUI views.End of example.
references/core-rules.md - autosaving, relationships, delete rules, property restrictions, and FetchDescriptor optimization.references/predicates.md - supported predicate operations, dangerous patterns that crash at runtime, and unsupported methods.references/cloudkit.md - CloudKit-specific constraints including uniqueness, optionality, and eventual consistency.references/indexing.md - database indexing for iOS 18+, including single and compound property indexes.references/class-inheritance.md - model subclassing for iOS 26+, including @available requirements, schema setup, and predicate filtering.Weekly Installs
1.2K
Repository
GitHub Stars
183
First Seen
14 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex1.2K
github-copilot1.2K
opencode1.2K
kimi-cli1.2K
gemini-cli1.2K
amp1.2K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装