axiom-swift
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSwift Language & Platform
Swift语言与平台
You MUST use this skill for ANY Swift idiom review, ownership/noncopyable types, Transferable/drag-and-drop, debug deep links, or tvOS development.
任何涉及Swift写法审查、所有权/不可复制类型、Transferable/拖放、调试深度链接或tvOS开发的场景,都必须使用本技能。
Quick Reference
快速参考
| Symptom / Task | Reference |
|---|---|
| Outdated Swift patterns (Date(), CGFloat, DateFormatter) | See |
| Foundation modernization (FormatStyle, URL.documentsDirectory) | See |
| Common Claude hallucinations in Swift code | See |
| Noncopyable types (~Copyable) | See |
| borrowing/consuming parameter ownership | See |
| InlineArray, Span, value generics | See |
| Reducing ARC overhead | See |
| Drag and drop (.draggable, .dropDestination) | See |
| Copy/paste (.copyable, PasteButton) | See |
| ShareLink, content sharing | See |
| Custom UTType declarations | See |
| TransferRepresentation choices | See |
| Debug-only deep links for simulator testing | See |
| Navigate to specific screens for screenshots | See |
| tvOS Focus Engine, Siri Remote input | See |
| tvOS storage constraints (no Documents dir) | See |
| tvOS text input, AVPlayer tuning | See |
| TVUIKit components | See |
| 场景/任务 | 参考文档 |
|---|---|
| 过时的Swift写法(Date()、CGFloat、DateFormatter) | 参见 |
| Foundation现代化(FormatStyle、URL.documentsDirectory) | 参见 |
| Swift代码中Claude常见的幻觉错误 | 参见 |
| 不可复制类型(~Copyable) | 参见 |
| borrowing/consuming参数所有权 | 参见 |
| InlineArray、Span、值泛型 | 参见 |
| 降低ARC开销 | 参见 |
| 拖放功能(.draggable、.dropDestination) | 参见 |
| 复制/粘贴(.copyable、PasteButton) | 参见 |
| ShareLink、内容分享 | 参见 |
| 自定义UTType声明 | 参见 |
| TransferRepresentation选择 | 参见 |
| 用于模拟器测试的仅调试深度链接 | 参见 |
| 导航到特定页面以截图 | 参见 |
| tvOS焦点引擎、Siri Remote输入 | 参见 |
| tvOS存储限制(无Documents目录) | 参见 |
| tvOS文本输入、AVPlayer调优 | 参见 |
| TVUIKit组件 | 参见 |
Decision Tree
决策树
dot
digraph swift {
start [label="Swift task" shape=ellipse];
what [label="What do you need?" shape=diamond];
start -> what;
what -> "skills/swift-modern.md" [label="modern idioms,\noutdated patterns,\nFoundation APIs"];
what -> "skills/ownership-conventions.md" [label="~Copyable, borrowing,\nconsuming, InlineArray,\nSpan, ARC reduction"];
what -> "skills/transferable-ref.md" [label="drag & drop, copy/paste,\nShareLink, UTTypes,\nTransferable conformance"];
what -> "skills/deep-link-debugging.md" [label="debug deep links,\nsimulator navigation,\nscreenshot automation"];
what -> "skills/tvos.md" [label="tvOS app,\nFocus Engine,\nSiri Remote, storage"];
}- Outdated Swift patterns / modern API replacements / Claude hallucinations? ->
skills/swift-modern.md - ~Copyable / borrowing / consuming / InlineArray / Span? ->
skills/ownership-conventions.md - Drag and drop / copy/paste / ShareLink / Transferable / UTTypes? ->
skills/transferable-ref.md - Debug deep links / simulator navigation / screenshot automation? ->
skills/deep-link-debugging.md - tvOS development / Focus Engine / Siri Remote / storage / AVPlayer? ->
skills/tvos.md - Swift concurrency (async/await, actors, Sendable) ->
/skill axiom-concurrency - Swift performance (COW, ARC, generics optimization) -> See axiom-performance (skills/swift-performance.md)
- Codable patterns (JSON, CodingKeys, enum serialization) -> See axiom-data (skills/codable.md)
dot
digraph swift {
start [label="Swift task" shape=ellipse];
what [label="What do you need?" shape=diamond];
start -> what;
what -> "skills/swift-modern.md" [label="modern idioms,\noutdated patterns,\nFoundation APIs"];
what -> "skills/ownership-conventions.md" [label="~Copyable, borrowing,\nconsuming, InlineArray,\nSpan, ARC reduction"];
what -> "skills/transferable-ref.md" [label="drag & drop, copy/paste,\nShareLink, UTTypes,\nTransferable conformance"];
what -> "skills/deep-link-debugging.md" [label="debug deep links,\nsimulator navigation,\nscreenshot automation"];
what -> "skills/tvos.md" [label="tvOS app,\nFocus Engine,\nSiri Remote, storage"];
}- 过时的Swift写法 / 现代API替代方案 / Claude幻觉错误? ->
skills/swift-modern.md - ~Copyable / borrowing / consuming / InlineArray / Span? ->
skills/ownership-conventions.md - 拖放 / 复制/粘贴 / ShareLink / Transferable / UTTypes? ->
skills/transferable-ref.md - 调试深度链接 / 模拟器导航 / 截图自动化? ->
skills/deep-link-debugging.md - tvOS开发 / 焦点引擎 / Siri Remote / 存储 / AVPlayer? ->
skills/tvos.md - Swift并发(async/await、actors、Sendable) ->
/skill axiom-concurrency - Swift性能优化(COW、ARC、泛型优化) -> 参见axiom-performance(skills/swift-performance.md)
- Codable写法(JSON、CodingKeys、枚举序列化) -> 参见axiom-data(skills/codable.md)
Conflict Resolution
冲突解决
swift vs concurrency: When Swift 6 concurrency errors appear:
- Use concurrency, NOT swift -- Concurrency errors are actor isolation / Sendable issues. covers concurrency posture (defaults), but detailed patterns live in axiom-concurrency.
skills/swift-modern.md
swift vs performance: When optimizing Swift code:
- Use swift for ownership if the question is borrowing/consuming/~Copyable/InlineArray/Span ->
skills/ownership-conventions.md - Use performance if the question is COW, ARC profiling, generic specialization, or Instruments workflows -> axiom-performance
swift vs swiftui: When implementing drag and drop or copy/paste:
- Use swift for Transferable conformance, representation choices, UTType declarations ->
skills/transferable-ref.md - Use swiftui for view-level modifiers (.draggable, .dropDestination styling, animations)
swift vs integration: When sharing content:
- ShareLink + Transferable -> use swift ()
skills/transferable-ref.md - UIActivityViewController customization, share extensions -> use integration
swift vs axiom-build: When tvOS build fails:
- Environment/Xcode issues -> use axiom-build first
- tvOS platform-specific code issues (Focus Engine, storage, no WebView) -> use swift ()
skills/tvos.md
swift vs concurrency:当出现Swift 6并发错误时:
- 使用concurrency,而非swift —— 并发错误涉及actor隔离/Sendable问题。涵盖并发姿态(默认设置),但详细写法在axiom-concurrency中。
skills/swift-modern.md
swift vs performance:当优化Swift代码时:
- 如果问题涉及borrowing/consuming/~Copyable/InlineArray/Span,使用swift处理所有权 ->
skills/ownership-conventions.md - 如果问题涉及COW、ARC分析、泛型特化或Instruments工作流,使用performance -> axiom-performance
swift vs swiftui:当实现拖放或复制/粘贴时:
- 使用swift处理Transferable合规性、表示选择、UTType声明 ->
skills/transferable-ref.md - 使用swiftui处理视图级修饰符(.draggable、.dropDestination样式、动画)
swift vs integration:当分享内容时:
- ShareLink + Transferable -> 使用swift ()
skills/transferable-ref.md - UIActivityViewController自定义、分享扩展 -> 使用integration
swift vs axiom-build:当tvOS构建失败时:
- 环境/Xcode问题 -> 优先使用axiom-build
- tvOS平台特定代码问题(焦点引擎、存储、无WebView) -> 使用swift ()
skills/tvos.md
Critical Patterns
核心模式
Modern Swift Idioms ():
skills/swift-modern.md- 12+ outdated patterns Claude defaults to (Date(), CGFloat, DateFormatter, DispatchQueue.main.async)
- Foundation modernization (FormatStyle, URL.documentsDirectory, .replacing())
- SwiftUI convenience APIs Claude misses (ContentUnavailableView.search, LabeledContent)
- Swift 6.3 concurrency posture defaults
- 9 common Claude hallucinations with corrections
Ownership & Noncopyable Types ():
skills/ownership-conventions.md- borrowing/consuming parameter modifiers with 7 patterns
- ~Copyable types: FileHandle pattern, limitations table, common compiler errors
- InlineArray: fixed-size stack-allocated arrays with value generics
- Span family: safe contiguous memory access replacing UnsafeBufferPointer
- Decision tree for when ownership modifiers help vs when to skip
Transferable & Sharing ():
skills/transferable-ref.md- Decision tree: CodableRepresentation vs DataRepresentation vs FileRepresentation vs ProxyRepresentation
- Drag and drop, copy/paste, ShareLink with complete SwiftUI API
- Custom UTType declarations (Swift + Info.plist, both required)
- 7 common errors with fixes (representation ordering, missing Info.plist, hit testing)
- UIKit bridging via NSItemProvider
Debug Deep Links ():
skills/deep-link-debugging.md- Debug-only URL scheme for simulator navigation
- NavigationPath integration for robust routing
- State configuration links (error states, empty states)
- Integration with /axiom:screenshot and simulator-tester agent
- 60-75% faster iteration with visual verification
tvOS Development ():
skills/tvos.md- Dual focus system (UIKit Focus Engine + SwiftUI @FocusState)
- Siri Remote input (two generations, three input layers)
- Storage constraints (no Documents directory, iCloud required)
- No WebView (JavaScriptCore only, no DOM)
- AVPlayer tuning, Menu button state machine
- TVUIKit components
现代Swift写法 ():
skills/swift-modern.md- Claude默认使用的12+种过时写法(Date()、CGFloat、DateFormatter、DispatchQueue.main.async)
- Foundation现代化(FormatStyle、URL.documentsDirectory、.replacing())
- Claude遗漏的SwiftUI便捷API(ContentUnavailableView.search、LabeledContent)
- Swift 6.3并发姿态默认设置
- 9种常见Claude幻觉错误及修正方案
所有权与不可复制类型 ():
skills/ownership-conventions.md- borrowing/consuming参数修饰符及7种写法
- ~Copyable类型:FileHandle模式、限制表、常见编译器错误
- InlineArray:基于栈分配的固定大小数组及值泛型
- Span系列:替代UnsafeBufferPointer的安全连续内存访问
- 何时使用所有权修饰符、何时跳过的决策树
Transferable与分享 ():
skills/transferable-ref.md- 决策树:CodableRepresentation vs DataRepresentation vs FileRepresentation vs ProxyRepresentation
- 拖放、复制/粘贴、ShareLink的完整SwiftUI API
- 自定义UTType声明(Swift + Info.plist,两者均需配置)
- 7种常见错误及修复方案(表示顺序、缺失Info.plist、命中测试)
- 通过NSItemProvider与UIKit桥接
调试深度链接 ():
skills/deep-link-debugging.md- 用于模拟器导航的仅调试URL scheme
- 集成NavigationPath实现可靠路由
- 状态配置链接(错误状态、空状态)
- 与/axiom:screenshot和simulator-tester agent集成
- 视觉验证迭代速度提升60-75%
tvOS开发 ():
skills/tvos.md- 双焦点系统(UIKit焦点引擎 + SwiftUI @FocusState)
- Siri Remote输入(两代设备,三层输入)
- 存储限制(无Documents目录,需使用iCloud)
- 无WebView(仅支持JavaScriptCore,无DOM)
- AVPlayer调优、菜单按钮状态机
- TVUIKit组件
Anti-Rationalization
常见误区澄清
| Thought | Reality |
|---|---|
| "Date() is fine, everyone uses it" | |
| "I don't need ownership modifiers" | For most code, correct. But ~Copyable types require them, and large value types in hot paths benefit measurably. |
| "Transferable is just Codable for drag and drop" | Transferable has 4 representation types, ordering rules, and Info.plist requirements. Getting it wrong causes silent cross-app failures. |
| "I'll just use the same code as iOS for tvOS" | tvOS has no Documents directory, no WebView, a dual focus system, and two generations of remote hardware. It compiles fine and fails at runtime. |
| "Debug deep links are overkill" | Manual navigation costs 2-3 minutes per iteration. Deep links cut it to 45 seconds. Over a debugging session, that's hours saved. |
| "CGFloat is what SwiftUI uses" | Swift 5.5+ has implicit Double-CGFloat bridging. Use Double everywhere except optionals, inout, and ObjC-bridged APIs. |
| "I'll add the Info.plist entry later" | Custom UTTypes work in-app without Info.plist but silently fail cross-app. This is the #1 "works in dev, fails in prod" Transferable issue. |
| "FormatStyle is too verbose" | |
| 错误想法 | 实际情况 |
|---|---|
| "Date()没问题,大家都在用" | |
| "我不需要所有权修饰符" | 大多数代码确实不需要,但~Copyable类型必须使用,且热点路径中的大型值类型能显著受益。 |
| "Transferable只是用于拖放的Codable" | Transferable有4种表示类型、排序规则及Info.plist要求。配置错误会导致跨应用静默失败。 |
| "我直接用iOS的代码开发tvOS就行" | tvOS没有Documents目录、无WebView、有双焦点系统,还有两代远程硬件。代码能编译通过,但运行时会失败。 |
| "调试深度链接没必要" | 手动导航每次迭代需要2-3分钟,深度链接可缩短至45秒。一次调试会话能节省数小时。 |
| "CGFloat是SwiftUI的标准用法" | Swift 5.5+支持Double与CGFloat隐式桥接。除可选类型、inout和ObjC桥接API外,所有场景都使用Double。 |
| "我以后再添加Info.plist条目" | 自定义UTTypes在应用内无需Info.plist也能工作,但跨应用时会静默失败。这是Transferable场景中“开发环境正常,生产环境失败”的头号问题。 |
| "FormatStyle太啰嗦了" | |
Example Invocations
调用示例
User: "Is this Swift code using modern patterns?"
-> Read:
skills/swift-modern.mdUser: "How do I use borrowing and consuming?"
-> Read:
skills/ownership-conventions.mdUser: "How do I make my model draggable?"
-> Read:
skills/transferable-ref.mdUser: "How do I implement ShareLink with a custom preview?"
-> Read:
skills/transferable-ref.mdUser: "I need debug deep links for simulator testing"
-> Read:
skills/deep-link-debugging.mdUser: "I'm building a tvOS app and focus navigation doesn't work"
-> Read:
skills/tvos.mdUser: "What is InlineArray and when should I use it?"
-> Read:
skills/ownership-conventions.mdUser: "My drag and drop works in-app but not across apps"
-> Read:
skills/transferable-ref.mdUser: "tvOS keeps losing my saved data"
-> Read:
skills/tvos.mdUser: "How do I optimize large struct passing?"
-> Read:
skills/ownership-conventions.mdUser: "I need to fix my async/await code"
-> See
/skill axiom-concurrencyUser: "Check my code for Swift 6 concurrency issues"
-> See
/skill axiom-concurrency用户:“这段Swift代码使用了现代写法吗?”
-> 参考:
skills/swift-modern.md用户:“如何使用borrowing和consuming?”
-> 参考:
skills/ownership-conventions.md用户:“如何让我的模型支持拖放?”
-> 参考:
skills/transferable-ref.md用户:“如何实现带自定义预览的ShareLink?”
-> 参考:
skills/transferable-ref.md用户:“我需要用于模拟器测试的调试深度链接”
-> 参考:
skills/deep-link-debugging.md用户:“我开发的tvOS应用焦点导航不工作”
-> 参考:
skills/tvos.md用户:“InlineArray是什么?什么时候应该使用它?”
-> 参考:
skills/ownership-conventions.md用户:“我的拖放在应用内正常,但跨应用不行”
-> 参考:
skills/transferable-ref.md用户:“tvOS总是丢失我的保存数据”
-> 参考:
skills/tvos.md用户:“如何优化大型结构体的传递?”
-> 参考:
skills/ownership-conventions.md用户:“我需要修复我的async/await代码”
-> 参见
/skill axiom-concurrency用户:“检查我的代码是否存在Swift 6并发问题”
-> 参见
/skill axiom-concurrency