buildanything 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +55 -0
  4. package/README.md +71 -61
  5. package/agents/ios-app-review-guardian.md +49 -0
  6. package/agents/ios-foundation-models-specialist.md +46 -0
  7. package/agents/ios-storekit-specialist.md +52 -0
  8. package/agents/ios-swift-architect.md +102 -0
  9. package/agents/ios-swift-search.md +130 -0
  10. package/agents/ios-swift-ui-design.md +104 -0
  11. package/commands/build.md +80 -176
  12. package/commands/fix.md +65 -0
  13. package/commands/setup.md +73 -0
  14. package/commands/ux-review.md +63 -0
  15. package/commands/verify.md +72 -0
  16. package/hooks/session-start +18 -1
  17. package/package.json +5 -2
  18. package/protocols/brainstorm.md +99 -0
  19. package/protocols/build-fix.md +52 -0
  20. package/protocols/cleanup.md +54 -0
  21. package/protocols/design.md +269 -0
  22. package/protocols/eval-harness.md +61 -0
  23. package/protocols/fake-data-detector.md +64 -0
  24. package/protocols/ios-context.md +235 -0
  25. package/protocols/ios-frameworks-map.md +323 -0
  26. package/protocols/ios-phase-branches.md +162 -0
  27. package/protocols/ios-preflight.md +27 -0
  28. package/protocols/metric-loop.md +93 -0
  29. package/protocols/planning.md +87 -0
  30. package/protocols/smoke-test.md +110 -0
  31. package/protocols/verify.md +67 -0
  32. package/protocols/web-phase-branches.md +201 -0
  33. package/skills/ios/_VENDORED.md +60 -0
  34. package/skills/ios/activitykit/LICENSE +131 -0
  35. package/skills/ios/activitykit/SKILL.md +505 -0
  36. package/skills/ios/activitykit/references/activitykit-patterns.md +868 -0
  37. package/skills/ios/app-intents/LICENSE +131 -0
  38. package/skills/ios/app-intents/SKILL.md +494 -0
  39. package/skills/ios/app-intents/references/appintents-advanced.md +1076 -0
  40. package/skills/ios/apple-on-device-ai/LICENSE +131 -0
  41. package/skills/ios/apple-on-device-ai/SKILL.md +505 -0
  42. package/skills/ios/apple-on-device-ai/references/coreml-conversion.md +425 -0
  43. package/skills/ios/apple-on-device-ai/references/coreml-optimization.md +344 -0
  44. package/skills/ios/apple-on-device-ai/references/foundation-models.md +508 -0
  45. package/skills/ios/apple-on-device-ai/references/mlx-swift.md +285 -0
  46. package/skills/ios/ios-26-platform/SKILL.md +53 -0
  47. package/skills/ios/ios-26-platform/references/automatic-adoption.md +161 -0
  48. package/skills/ios/ios-26-platform/references/backward-compat.md +238 -0
  49. package/skills/ios/ios-26-platform/references/liquid-glass.md +255 -0
  50. package/skills/ios/ios-26-platform/references/swiftui-apis.md +277 -0
  51. package/skills/ios/ios-26-platform/references/toolbar-navigation.md +250 -0
  52. package/skills/ios/ios-bootstrap/SKILL.md +98 -0
  53. package/skills/ios/ios-bootstrap/references/apple-docs-mcp-config.md +28 -0
  54. package/skills/ios/ios-bootstrap/references/new-project-dialog.md +41 -0
  55. package/skills/ios/ios-bootstrap/references/xcode-mcp-config.md +29 -0
  56. package/skills/ios/ios-debugger-agent/LICENSE +21 -0
  57. package/skills/ios/ios-debugger-agent/SKILL.md +58 -0
  58. package/skills/ios/ios-debugger-agent/agents/openai.yaml +4 -0
  59. package/skills/ios/ios-entitlements-generator/SKILL.md +47 -0
  60. package/skills/ios/ios-hig/SKILL.md +41 -0
  61. package/skills/ios/ios-hig/references/accessibility.md +81 -0
  62. package/skills/ios/ios-hig/references/content.md +142 -0
  63. package/skills/ios/ios-hig/references/feedback.md +123 -0
  64. package/skills/ios/ios-hig/references/interaction.md +199 -0
  65. package/skills/ios/ios-hig/references/performance-platform.md +129 -0
  66. package/skills/ios/ios-hig/references/privacy-permissions.md +181 -0
  67. package/skills/ios/ios-hig/references/visual-design.md +84 -0
  68. package/skills/ios/ios-info-plist-hardening/SKILL.md +130 -0
  69. package/skills/ios/ios-maestro-flow-author/SKILL.md +68 -0
  70. package/skills/ios/ios-maestro-flow-author/references/input-and-scroll.yaml +17 -0
  71. package/skills/ios/ios-maestro-flow-author/references/modal-and-dismiss.yaml +14 -0
  72. package/skills/ios/ios-maestro-flow-author/references/onboarding-flow.yaml +16 -0
  73. package/skills/ios/ios-maestro-flow-author/references/tab-navigation.yaml +13 -0
  74. package/skills/ios/ios-maestro-flow-author/references/tap-and-assert.yaml +9 -0
  75. package/skills/ios/swift-accessibility/LICENSE +21 -0
  76. package/skills/ios/swift-accessibility/SKILL.md +371 -0
  77. package/skills/ios/swift-accessibility/examples/before-after-appkit.md +446 -0
  78. package/skills/ios/swift-accessibility/examples/before-after-swiftui.md +441 -0
  79. package/skills/ios/swift-accessibility/examples/before-after-uikit.md +464 -0
  80. package/skills/ios/swift-accessibility/references/assistive-access.md +441 -0
  81. package/skills/ios/swift-accessibility/references/display-settings.md +491 -0
  82. package/skills/ios/swift-accessibility/references/dynamic-type.md +420 -0
  83. package/skills/ios/swift-accessibility/references/media-accessibility.md +421 -0
  84. package/skills/ios/swift-accessibility/references/motor-input.md +393 -0
  85. package/skills/ios/swift-accessibility/references/nutrition-labels.md +362 -0
  86. package/skills/ios/swift-accessibility/references/platform-specifics.md +515 -0
  87. package/skills/ios/swift-accessibility/references/semantic-structure.md +585 -0
  88. package/skills/ios/swift-accessibility/references/testing-auditing.md +507 -0
  89. package/skills/ios/swift-accessibility/references/voice-control.md +317 -0
  90. package/skills/ios/swift-accessibility/references/voiceover-swiftui.md +584 -0
  91. package/skills/ios/swift-accessibility/references/voiceover-uikit.md +519 -0
  92. package/skills/ios/swift-accessibility/references/wcag-mapping.md +167 -0
  93. package/skills/ios/swift-accessibility/resources/audit-template.swift +128 -0
  94. package/skills/ios/swift-accessibility/resources/qa-checklist.md +258 -0
  95. package/skills/ios/swift-concurrency/LICENSE +21 -0
  96. package/skills/ios/swift-concurrency/SKILL.md +171 -0
  97. package/skills/ios/swift-concurrency/references/_index.md +50 -0
  98. package/skills/ios/swift-concurrency/references/actors.md +660 -0
  99. package/skills/ios/swift-concurrency/references/async-algorithms.md +847 -0
  100. package/skills/ios/swift-concurrency/references/async-await-basics.md +266 -0
  101. package/skills/ios/swift-concurrency/references/async-sequences.md +710 -0
  102. package/skills/ios/swift-concurrency/references/core-data.md +560 -0
  103. package/skills/ios/swift-concurrency/references/glossary.md +135 -0
  104. package/skills/ios/swift-concurrency/references/linting.md +155 -0
  105. package/skills/ios/swift-concurrency/references/memory-management.md +569 -0
  106. package/skills/ios/swift-concurrency/references/migration.md +1104 -0
  107. package/skills/ios/swift-concurrency/references/performance.md +593 -0
  108. package/skills/ios/swift-concurrency/references/sendable.md +598 -0
  109. package/skills/ios/swift-concurrency/references/tasks.md +636 -0
  110. package/skills/ios/swift-concurrency/references/testing.md +592 -0
  111. package/skills/ios/swift-concurrency/references/threading.md +495 -0
  112. package/skills/ios/swift-security-expert/LICENSE +21 -0
  113. package/skills/ios/swift-security-expert/SKILL.md +470 -0
  114. package/skills/ios/swift-security-expert/references/biometric-authentication.md +565 -0
  115. package/skills/ios/swift-security-expert/references/certificate-trust.md +592 -0
  116. package/skills/ios/swift-security-expert/references/common-anti-patterns.md +690 -0
  117. package/skills/ios/swift-security-expert/references/compliance-owasp-mapping.md +537 -0
  118. package/skills/ios/swift-security-expert/references/credential-storage-patterns.md +721 -0
  119. package/skills/ios/swift-security-expert/references/cryptokit-public-key.md +505 -0
  120. package/skills/ios/swift-security-expert/references/cryptokit-symmetric.md +497 -0
  121. package/skills/ios/swift-security-expert/references/keychain-access-control.md +508 -0
  122. package/skills/ios/swift-security-expert/references/keychain-fundamentals.md +596 -0
  123. package/skills/ios/swift-security-expert/references/keychain-item-classes.md +476 -0
  124. package/skills/ios/swift-security-expert/references/keychain-sharing.md +458 -0
  125. package/skills/ios/swift-security-expert/references/migration-legacy-stores.md +727 -0
  126. package/skills/ios/swift-security-expert/references/secure-enclave.md +539 -0
  127. package/skills/ios/swift-security-expert/references/testing-security-code.md +781 -0
  128. package/skills/ios/swift-testing-expert/LICENSE +21 -0
  129. package/skills/ios/swift-testing-expert/SKILL.md +79 -0
  130. package/skills/ios/swift-testing-expert/references/_index.md +12 -0
  131. package/skills/ios/swift-testing-expert/references/async-testing-and-waiting.md +127 -0
  132. package/skills/ios/swift-testing-expert/references/expectations.md +145 -0
  133. package/skills/ios/swift-testing-expert/references/fundamentals.md +141 -0
  134. package/skills/ios/swift-testing-expert/references/migration-from-xctest.md +127 -0
  135. package/skills/ios/swift-testing-expert/references/parallelization-and-isolation.md +95 -0
  136. package/skills/ios/swift-testing-expert/references/parameterized-testing.md +284 -0
  137. package/skills/ios/swift-testing-expert/references/performance-and-best-practices.md +187 -0
  138. package/skills/ios/swift-testing-expert/references/traits-and-tags.md +114 -0
  139. package/skills/ios/swift-testing-expert/references/xcode-workflows.md +70 -0
  140. package/skills/ios/swiftdata-pro/LICENSE +21 -0
  141. package/skills/ios/swiftdata-pro/SKILL.md +102 -0
  142. package/skills/ios/swiftdata-pro/agents/openai.yaml +10 -0
  143. package/skills/ios/swiftdata-pro/assets/swiftdata-pro-icon.png +0 -0
  144. package/skills/ios/swiftdata-pro/assets/swiftdata-pro-icon.svg +29 -0
  145. package/skills/ios/swiftdata-pro/references/class-inheritance.md +104 -0
  146. package/skills/ios/swiftdata-pro/references/cloudkit.md +10 -0
  147. package/skills/ios/swiftdata-pro/references/core-rules.md +20 -0
  148. package/skills/ios/swiftdata-pro/references/indexing.md +27 -0
  149. package/skills/ios/swiftdata-pro/references/predicates.md +73 -0
  150. package/skills/ios/swiftui-design-principles/AGENTS.md +21 -0
  151. package/skills/ios/swiftui-design-principles/LICENSE +21 -0
  152. package/skills/ios/swiftui-design-principles/README.md +41 -0
  153. package/skills/ios/swiftui-design-principles/SKILL.md +605 -0
  154. package/skills/ios/swiftui-design-principles/metadata.json +10 -0
  155. package/skills/ios/swiftui-liquid-glass/LICENSE +21 -0
  156. package/skills/ios/swiftui-liquid-glass/SKILL.md +95 -0
  157. package/skills/ios/swiftui-liquid-glass/agents/openai.yaml +4 -0
  158. package/skills/ios/swiftui-liquid-glass/references/liquid-glass.md +280 -0
  159. package/skills/ios/swiftui-performance-audit/LICENSE +21 -0
  160. package/skills/ios/swiftui-performance-audit/SKILL.md +111 -0
  161. package/skills/ios/swiftui-performance-audit/agents/openai.yaml +4 -0
  162. package/skills/ios/swiftui-performance-audit/references/code-smells.md +150 -0
  163. package/skills/ios/swiftui-performance-audit/references/demystify-swiftui-performance-wwdc23.md +46 -0
  164. package/skills/ios/swiftui-performance-audit/references/optimizing-swiftui-performance-instruments.md +29 -0
  165. package/skills/ios/swiftui-performance-audit/references/profiling-intake.md +44 -0
  166. package/skills/ios/swiftui-performance-audit/references/report-template.md +47 -0
  167. package/skills/ios/swiftui-performance-audit/references/understanding-hangs-in-your-app.md +33 -0
  168. package/skills/ios/swiftui-performance-audit/references/understanding-improving-swiftui-performance.md +52 -0
  169. package/skills/ios/swiftui-pro/LICENSE +21 -0
  170. package/skills/ios/swiftui-pro/SKILL.md +108 -0
  171. package/skills/ios/swiftui-pro/agents/openai.yaml +10 -0
  172. package/skills/ios/swiftui-pro/assets/swiftui-pro-icon.png +0 -0
  173. package/skills/ios/swiftui-pro/assets/swiftui-pro-icon.svg +29 -0
  174. package/skills/ios/swiftui-pro/references/accessibility.md +13 -0
  175. package/skills/ios/swiftui-pro/references/api.md +39 -0
  176. package/skills/ios/swiftui-pro/references/data.md +43 -0
  177. package/skills/ios/swiftui-pro/references/design.md +31 -0
  178. package/skills/ios/swiftui-pro/references/hygiene.md +9 -0
  179. package/skills/ios/swiftui-pro/references/navigation.md +14 -0
  180. package/skills/ios/swiftui-pro/references/performance.md +46 -0
  181. package/skills/ios/swiftui-pro/references/swift.md +56 -0
  182. package/skills/ios/swiftui-pro/references/views.md +35 -0
  183. package/skills/ios/swiftui-ui-patterns/LICENSE +21 -0
  184. package/skills/ios/swiftui-ui-patterns/SKILL.md +100 -0
  185. package/skills/ios/swiftui-ui-patterns/agents/openai.yaml +4 -0
  186. package/skills/ios/swiftui-ui-patterns/references/app-wiring.md +201 -0
  187. package/skills/ios/swiftui-ui-patterns/references/async-state.md +96 -0
  188. package/skills/ios/swiftui-ui-patterns/references/components-index.md +50 -0
  189. package/skills/ios/swiftui-ui-patterns/references/controls.md +57 -0
  190. package/skills/ios/swiftui-ui-patterns/references/deeplinks.md +66 -0
  191. package/skills/ios/swiftui-ui-patterns/references/focus.md +90 -0
  192. package/skills/ios/swiftui-ui-patterns/references/form.md +97 -0
  193. package/skills/ios/swiftui-ui-patterns/references/grids.md +71 -0
  194. package/skills/ios/swiftui-ui-patterns/references/haptics.md +71 -0
  195. package/skills/ios/swiftui-ui-patterns/references/input-toolbar.md +51 -0
  196. package/skills/ios/swiftui-ui-patterns/references/lightweight-clients.md +93 -0
  197. package/skills/ios/swiftui-ui-patterns/references/list.md +86 -0
  198. package/skills/ios/swiftui-ui-patterns/references/loading-placeholders.md +38 -0
  199. package/skills/ios/swiftui-ui-patterns/references/macos-settings.md +71 -0
  200. package/skills/ios/swiftui-ui-patterns/references/matched-transitions.md +59 -0
  201. package/skills/ios/swiftui-ui-patterns/references/media.md +73 -0
  202. package/skills/ios/swiftui-ui-patterns/references/menu-bar.md +101 -0
  203. package/skills/ios/swiftui-ui-patterns/references/navigationstack.md +159 -0
  204. package/skills/ios/swiftui-ui-patterns/references/overlay.md +45 -0
  205. package/skills/ios/swiftui-ui-patterns/references/performance.md +62 -0
  206. package/skills/ios/swiftui-ui-patterns/references/previews.md +48 -0
  207. package/skills/ios/swiftui-ui-patterns/references/scroll-reveal.md +133 -0
  208. package/skills/ios/swiftui-ui-patterns/references/scrollview.md +87 -0
  209. package/skills/ios/swiftui-ui-patterns/references/searchable.md +71 -0
  210. package/skills/ios/swiftui-ui-patterns/references/sheets.md +155 -0
  211. package/skills/ios/swiftui-ui-patterns/references/split-views.md +72 -0
  212. package/skills/ios/swiftui-ui-patterns/references/tabview.md +114 -0
  213. package/skills/ios/swiftui-ui-patterns/references/theming.md +71 -0
  214. package/skills/ios/swiftui-ui-patterns/references/title-menus.md +93 -0
  215. package/skills/ios/swiftui-ui-patterns/references/top-bar.md +49 -0
  216. package/skills/ios/swiftui-view-refactor/LICENSE +21 -0
  217. package/skills/ios/swiftui-view-refactor/SKILL.md +207 -0
  218. package/skills/ios/swiftui-view-refactor/agents/openai.yaml +4 -0
  219. package/skills/ios/swiftui-view-refactor/references/mv-patterns.md +161 -0
  220. package/skills/ios/widgetkit/LICENSE +131 -0
  221. package/skills/ios/widgetkit/SKILL.md +502 -0
  222. package/skills/ios/widgetkit/references/widgetkit-advanced.md +871 -0
@@ -0,0 +1,598 @@
1
+ # Sendable
2
+
3
+ Use this when:
4
+
5
+ - A value or reference type must cross an isolation boundary safely.
6
+ - You are resolving "non-Sendable type" compiler diagnostics.
7
+ - You need to decide between value types, `@unchecked Sendable`, actors, or region-based isolation.
8
+
9
+ Skip this file if:
10
+
11
+ - The issue is about which actor should own the state. Use `actors.md`.
12
+ - The issue is about how async functions execute. Use `threading.md`.
13
+
14
+ Jump to:
15
+
16
+ - Isolation Domains
17
+ - Value Types (Structs, Enums)
18
+ - Reference Types (Classes)
19
+ - Functions and Closures (@Sendable)
20
+ - @unchecked Sendable
21
+ - Region-Based Isolation / `sending`
22
+ - Global Variables
23
+ - Decision Tree
24
+
25
+ ## What is Sendable?
26
+
27
+ `Sendable` indicates a type is safe to share across isolation domains (actors, tasks, threads). The compiler verifies thread-safety at compile time.
28
+
29
+ ```swift
30
+ public protocol Sendable {}
31
+ ```
32
+
33
+ Empty protocol, but triggers compiler verification of thread-safety.
34
+
35
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.1: Explaining the concept of Sendable in Swift](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
36
+
37
+ ## Isolation Domains
38
+
39
+ Three types of isolation in Swift Concurrency:
40
+
41
+ ### 1. Nonisolated (default)
42
+
43
+ No concurrency restrictions, but can't modify isolated state:
44
+
45
+ ```swift
46
+ func computeValue(a: Int, b: Int) -> Int {
47
+ return a + b
48
+ }
49
+ ```
50
+
51
+ ### 2. Actor-isolated
52
+
53
+ Dedicated isolation domain with serialized access:
54
+
55
+ ```swift
56
+ actor Library {
57
+ var books: [String] = []
58
+
59
+ func addBook(_ title: String) {
60
+ books.append(title)
61
+ }
62
+ }
63
+
64
+ // External access requires await
65
+ await library.addBook("Swift Concurrency")
66
+ ```
67
+
68
+ ### 3. Global actor-isolated
69
+
70
+ Shared isolation domain across types:
71
+
72
+ ```swift
73
+ @MainActor
74
+ func updateUI() {
75
+ // Runs on main thread
76
+ }
77
+ ```
78
+
79
+ ## Data Races vs Race Conditions
80
+
81
+ ### Data Race
82
+
83
+ Multiple threads access shared mutable state, at least one writes, without synchronization:
84
+
85
+ ```swift
86
+ // ⚠️ Data race
87
+ var counter = 0
88
+ DispatchQueue.global().async { counter += 1 }
89
+ DispatchQueue.global().async { counter += 1 }
90
+ ```
91
+
92
+ **Detection**: Enable Thread Sanitizer in scheme settings.
93
+
94
+ **Prevention**: Use actors or Sendable types:
95
+
96
+ ```swift
97
+ actor Counter {
98
+ private var value = 0
99
+
100
+ func increment() {
101
+ value += 1
102
+ }
103
+ }
104
+ ```
105
+
106
+ ### Race Condition
107
+
108
+ Timing-dependent behavior leading to unpredictable results:
109
+
110
+ ```swift
111
+ let counter = Counter()
112
+
113
+ for _ in 1...10 {
114
+ Task { await counter.increment() }
115
+ }
116
+
117
+ // May print inconsistent values
118
+ print(await counter.getValue())
119
+ ```
120
+
121
+ **Key difference**: Swift Concurrency prevents data races but not race conditions. You must still ensure proper sequencing.
122
+
123
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.2: Understanding Data Races vs. Race Conditions: Key Differences Explained](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
124
+
125
+ ## Value Types (Structs, Enums)
126
+
127
+ ### Implicit conformance
128
+
129
+ Non-public structs/enums with Sendable members:
130
+
131
+ ```swift
132
+ // Implicitly Sendable
133
+ struct Person {
134
+ var name: String
135
+ }
136
+ ```
137
+
138
+ ### Explicit conformance required
139
+
140
+ Public types need explicit declaration:
141
+
142
+ ```swift
143
+ public struct Person: Sendable {
144
+ var name: String
145
+ }
146
+ ```
147
+
148
+ **Why**: Compiler can't verify internal details of public types across modules.
149
+
150
+ ### Frozen types
151
+
152
+ Public frozen types can be implicitly Sendable:
153
+
154
+ ```swift
155
+ @frozen
156
+ public struct Point: Sendable {
157
+ public var x: Double
158
+ public var y: Double
159
+ }
160
+ ```
161
+
162
+ ### All members must be Sendable
163
+
164
+ ```swift
165
+ public struct Person: Sendable {
166
+ var name: String
167
+ var hometown: Location // Must also be Sendable
168
+ }
169
+
170
+ public struct Location: Sendable {
171
+ var name: String
172
+ }
173
+ ```
174
+
175
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.3: Conforming your code to the Sendable protocol](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
176
+
177
+ ### Copy-on-write makes mutability safe
178
+
179
+ ```swift
180
+ public struct Person: Sendable {
181
+ var name: String // Mutable but safe due to COW
182
+ }
183
+ ```
184
+
185
+ Each mutation creates a copy, preventing concurrent access to same instance.
186
+
187
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.4: Sendable and Value Types](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
188
+
189
+ ## Reference Types (Classes)
190
+
191
+ ### Requirements for Sendable classes
192
+
193
+ Must be:
194
+ 1. `final` (no inheritance)
195
+ 2. Immutable stored properties only
196
+ 3. All properties Sendable
197
+ 4. No superclass or `NSObject` only
198
+
199
+ ```swift
200
+ final class User: Sendable {
201
+ let name: String
202
+ let id: Int
203
+
204
+ init(name: String, id: Int) {
205
+ self.name = name
206
+ self.id = id
207
+ }
208
+ }
209
+ ```
210
+
211
+ ### Why non-final classes can't be Sendable
212
+
213
+ Child classes could introduce unsafe mutability:
214
+
215
+ ```swift
216
+ // Can't be Sendable
217
+ class Purchaser {
218
+ func purchase() { }
219
+ }
220
+
221
+ // Could introduce data races
222
+ class GamePurchaser: Purchaser {
223
+ var credits: Int = 0 // Mutable!
224
+ }
225
+ ```
226
+
227
+ ### Actor isolation makes classes Sendable
228
+
229
+ ```swift
230
+ @MainActor
231
+ class ViewModel {
232
+ var data: [Item] = [] // Safe due to actor isolation
233
+ }
234
+ // Implicitly Sendable
235
+ ```
236
+
237
+ ### Composition over inheritance
238
+
239
+ ```swift
240
+ final class Purchaser: Sendable {
241
+ func purchase() { }
242
+ }
243
+
244
+ final class GamePurchaser {
245
+ let purchaser: Purchaser = Purchaser()
246
+ // Handle credits separately
247
+ }
248
+ ```
249
+
250
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.5: Sendable and Reference Types](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
251
+
252
+ ## Functions and Closures (@Sendable)
253
+
254
+ Mark functions/closures that cross isolation domains:
255
+
256
+ ```swift
257
+ actor ContactsStore {
258
+ func removeAll(_ shouldRemove: @Sendable (Contact) -> Bool) async {
259
+ contacts.removeAll { shouldRemove($0) }
260
+ }
261
+ }
262
+ ```
263
+
264
+ ### Captured values must be Sendable
265
+
266
+ ```swift
267
+ let query = "search"
268
+
269
+ // ✅ Immutable capture
270
+ store.filter { contact in
271
+ contact.name.contains(query)
272
+ }
273
+
274
+ var query = "search"
275
+
276
+ // ❌ Mutable capture
277
+ store.filter { contact in
278
+ contact.name.contains(query) // Error
279
+ }
280
+ ```
281
+
282
+ ### Capture lists for mutable values
283
+
284
+ ```swift
285
+ var query = "search"
286
+
287
+ // ✅ Capture immutable snapshot
288
+ store.filter { [query] contact in
289
+ contact.name.contains(query)
290
+ }
291
+ ```
292
+
293
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.6: Using @Sendable with closures](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
294
+
295
+ ## @unchecked Sendable
296
+
297
+ **Use as last resort.** Tells compiler to skip verification—you guarantee thread-safety.
298
+
299
+ ### When to use
300
+
301
+ Manual locking mechanisms the compiler can't verify:
302
+
303
+ ```swift
304
+ final class Cache: @unchecked Sendable {
305
+ private let lock = NSLock()
306
+ private var items: [String: Data] = [:]
307
+
308
+ func get(_ key: String) -> Data? {
309
+ lock.lock()
310
+ defer { lock.unlock() }
311
+ return items[key]
312
+ }
313
+
314
+ func set(_ key: String, value: Data) {
315
+ lock.lock()
316
+ defer { lock.unlock() }
317
+ items[key] = value
318
+ }
319
+ }
320
+ ```
321
+
322
+ ### Risks
323
+
324
+ - No compile-time safety
325
+ - Easy to introduce data races
326
+ - Must manually ensure all access uses lock
327
+
328
+ ```swift
329
+ final class Cache: @unchecked Sendable {
330
+ private let lock = NSLock()
331
+ private var items: [String: Data] = [:]
332
+
333
+ // ⚠️ Forgot lock - data race!
334
+ var count: Int {
335
+ items.count
336
+ }
337
+ }
338
+ ```
339
+
340
+ **Better**: Use actor instead:
341
+
342
+ ```swift
343
+ actor Cache {
344
+ private var items: [String: Data] = [:]
345
+
346
+ var count: Int { items.count }
347
+
348
+ func get(_ key: String) -> Data? {
349
+ items[key]
350
+ }
351
+
352
+ func set(_ key: String, value: Data) {
353
+ items[key] = value
354
+ }
355
+ }
356
+ ```
357
+
358
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.7: Using @unchecked Sendable](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
359
+
360
+ ## Region-Based Isolation
361
+
362
+ Compiler allows non-Sendable types in same scope:
363
+
364
+ ```swift
365
+ class Article {
366
+ var title: String
367
+ init(title: String) { self.title = title }
368
+ }
369
+
370
+ func check() {
371
+ let article = Article(title: "Swift")
372
+
373
+ Task {
374
+ print(article.title) // ✅ OK - same region
375
+ }
376
+ }
377
+ ```
378
+
379
+ **Why**: No mutation after transfer, so no data race risk.
380
+
381
+ ### Breaks when accessed after transfer
382
+
383
+ ```swift
384
+ func check() {
385
+ let article = Article(title: "Swift")
386
+
387
+ Task {
388
+ print(article.title)
389
+ }
390
+
391
+ print(article.title) // ❌ Error - accessed after transfer
392
+ }
393
+ ```
394
+
395
+ ## The sending Keyword
396
+
397
+ Enforces ownership transfer for non-Sendable types:
398
+
399
+ ### Parameter values
400
+
401
+ ```swift
402
+ actor Logger {
403
+ func log(article: Article) {
404
+ print(article.title)
405
+ }
406
+ }
407
+
408
+ func printTitle(article: sending Article) async {
409
+ let logger = Logger()
410
+ await logger.log(article: article)
411
+ }
412
+
413
+ // Usage
414
+ let article = Article(title: "Swift")
415
+ await printTitle(article: article)
416
+ // article no longer accessible here
417
+ ```
418
+
419
+ ### Return values
420
+
421
+ ```swift
422
+ @SomeActor
423
+ func createArticle(title: String) -> sending Article {
424
+ return Article(title: title)
425
+ }
426
+ ```
427
+
428
+ Transfers ownership to caller's region.
429
+
430
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.8: Understanding region-based isolation and the sending keyword](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
431
+
432
+ ## Global Variables
433
+
434
+ Must be concurrency-safe since accessible from any context.
435
+
436
+ ### Problem
437
+
438
+ ```swift
439
+ class ImageCache {
440
+ static var shared = ImageCache() // ⚠️ Not concurrency-safe
441
+ }
442
+ ```
443
+
444
+ ### Solution 1: Actor isolation
445
+
446
+ ```swift
447
+ @MainActor
448
+ class ImageCache {
449
+ static var shared = ImageCache()
450
+ }
451
+ ```
452
+
453
+ ### Solution 2: Immutable + Sendable
454
+
455
+ ```swift
456
+ final class ImageCache: Sendable {
457
+ static let shared = ImageCache()
458
+ }
459
+ ```
460
+
461
+ ### Solution 3: nonisolated(unsafe)
462
+
463
+ **Last resort** - you guarantee safety:
464
+
465
+ ```swift
466
+ struct APIProvider: Sendable {
467
+ nonisolated(unsafe) static private(set) var shared: APIProvider!
468
+
469
+ static func configure(apiURL: URL) {
470
+ shared = APIProvider(apiURL: apiURL)
471
+ }
472
+ }
473
+ ```
474
+
475
+ Use `private(set)` to limit mutation points.
476
+
477
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.9: Concurrency-safe global variables](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
478
+
479
+ ## Custom Locks + Sendable
480
+
481
+ ### Legacy code with locks
482
+
483
+ ```swift
484
+ final class BankAccount: @unchecked Sendable {
485
+ private var balance: Int = 0
486
+ private let lock = NSLock()
487
+
488
+ func deposit(amount: Int) {
489
+ lock.lock()
490
+ balance += amount
491
+ lock.unlock()
492
+ }
493
+
494
+ func getBalance() -> Int {
495
+ lock.lock()
496
+ defer { lock.unlock() }
497
+ return balance
498
+ }
499
+ }
500
+ ```
501
+
502
+ ### Migration strategy
503
+
504
+ **New code**: Use actors
505
+
506
+ **Existing code**:
507
+ 1. If isolated and small scope → migrate to actor
508
+ 2. If widely used → use `@unchecked Sendable`, file migration ticket
509
+
510
+ ```swift
511
+ // Better: Migrate to actor
512
+ actor BankAccount {
513
+ private var balance: Int = 0
514
+
515
+ func deposit(amount: Int) {
516
+ balance += amount
517
+ }
518
+
519
+ func getBalance() -> Int {
520
+ balance
521
+ }
522
+ }
523
+ ```
524
+
525
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 4.10: Combining Sendable with custom Locks](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
526
+
527
+ ## Decision Tree
528
+
529
+ ```
530
+ Need to share type across isolation domains?
531
+ ├─ Value type (struct/enum)?
532
+ │ ├─ Public? → Add explicit Sendable
533
+ │ └─ Internal? → Implicit Sendable (if members Sendable)
534
+
535
+ ├─ Reference type (class)?
536
+ │ ├─ Can be final + immutable? → Sendable
537
+ │ ├─ Needs mutation?
538
+ │ │ ├─ Can use actor? → Use actor (automatic Sendable)
539
+ │ │ ├─ Main thread only? → @MainActor
540
+ │ │ └─ Has custom lock? → @unchecked Sendable (temporary)
541
+ │ └─ Can be struct instead? → Refactor to struct
542
+
543
+ └─ Function/closure? → @Sendable attribute
544
+ ```
545
+
546
+ ## Common Patterns
547
+
548
+ ### Restructure to avoid non-Sendable dependencies
549
+
550
+ ```swift
551
+ // Instead of storing non-Sendable type
552
+ public struct Person: Sendable {
553
+ var hometown: String // Just the name
554
+
555
+ init(hometown: Location) {
556
+ self.hometown = hometown.name
557
+ }
558
+ }
559
+ ```
560
+
561
+ ### Prefer actors for mutable state
562
+
563
+ ```swift
564
+ // Instead of @unchecked Sendable with locks
565
+ actor Cache {
566
+ private var items: [String: Data] = [:]
567
+
568
+ func get(_ key: String) -> Data? {
569
+ items[key]
570
+ }
571
+ }
572
+ ```
573
+
574
+ ### Use @MainActor for UI-bound types
575
+
576
+ ```swift
577
+ @MainActor
578
+ class ViewModel: ObservableObject {
579
+ @Published var items: [Item] = []
580
+ }
581
+ ```
582
+
583
+ ## Best Practices
584
+
585
+ 1. **Prefer value types** - structs/enums are easier to make Sendable
586
+ 2. **Use actors for mutable state** - automatic thread-safety
587
+ 3. **Avoid @unchecked Sendable** - use only for proven thread-safe code
588
+ 4. **Mark public types explicitly** - don't rely on implicit conformance
589
+ 5. **Ensure all members Sendable** - one non-Sendable breaks the chain
590
+ 6. **Use @MainActor for UI types** - simple isolation for view models
591
+ 7. **Capture immutably** - use capture lists for mutable variables
592
+ 8. **Test with Thread Sanitizer** - catches runtime data races
593
+ 9. **File migration tickets** - track @unchecked Sendable usage
594
+
595
+ ## Further Learning
596
+
597
+ For migration strategies, real-world examples, and actor patterns, see [Swift Concurrency Course](https://www.swiftconcurrencycourse.com).
598
+