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,495 @@
1
+ # Threading
2
+
3
+ Use this when:
4
+
5
+ - You need to understand the relationship between tasks and threads.
6
+ - You are debugging suspension points, actor reentrancy, or unexpected execution contexts.
7
+ - You need Swift 6.2 behavior guidance (`nonisolated async`, `@concurrent`, `nonisolated(nonsending)`).
8
+
9
+ Skip this file if:
10
+
11
+ - You mainly need to protect mutable state. Use `actors.md`.
12
+ - You need to make types safe to transfer. Use `sendable.md`.
13
+
14
+ Jump to:
15
+
16
+ - Core Concepts (Tasks vs Threads)
17
+ - Cooperative Thread Pool
18
+ - Suspension Points and Actor Reentrancy
19
+ - Swift 6.2 Changes (SE-461, SE-466)
20
+ - Default Isolation Domain
21
+ - Debugging Thread Execution
22
+ - Common Misconceptions
23
+ - Migration Strategy
24
+
25
+ ## Core Concepts
26
+
27
+ ### What is a Thread?
28
+
29
+ System-level resource that runs instructions. High overhead for creation and switching. Swift Concurrency abstracts thread management away.
30
+
31
+ ### Tasks vs Threads
32
+
33
+ **Tasks** are units of async work, not tied to specific threads. Swift dynamically schedules tasks on available threads from a cooperative pool.
34
+
35
+ **Key insight**: No direct relationship between one task and one thread.
36
+
37
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 7.1: How Threads relate to Tasks](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
38
+
39
+ **Important (Swift 6+)**: Avoid using `Thread.current` inside async contexts. In Swift 6 language mode, `Thread.current` is unavailable from asynchronous contexts and will fail to compile. Prefer reasoning in terms of isolation domains; use Instruments and the debugger to observe execution when needed.
40
+
41
+ ## Cooperative Thread Pool
42
+
43
+ Swift creates only as many threads as CPU cores. Tasks share these threads efficiently.
44
+
45
+ ### How it works
46
+
47
+ 1. **Limited threads**: Number matches CPU cores
48
+ 2. **Task scheduling**: Tasks scheduled onto available threads
49
+ 3. **Suspension**: At `await`, task suspends, thread freed for other work
50
+ 4. **Resumption**: Task resumes on any available thread (not necessarily the same one)
51
+
52
+ ```swift
53
+ func example() async {
54
+ print("Started on: \(Thread.current)")
55
+
56
+ try await Task.sleep(for: .seconds(1))
57
+
58
+ print("Resumed on: \(Thread.current)") // Likely different thread
59
+ }
60
+ ```
61
+
62
+ ### Benefits over GCD
63
+
64
+ **Prevents thread explosion**:
65
+ - No excessive thread creation
66
+ - No high memory overhead from idle threads
67
+ - No excessive context switching
68
+ - No priority inversion
69
+
70
+ **Better performance**:
71
+ - Fewer threads = less context switching
72
+ - Continuations instead of blocking
73
+ - CPU cores stay busy efficiently
74
+
75
+ ## Threading Mindset → Isolation Mindset
76
+
77
+ ### Old way (GCD)
78
+
79
+ ```swift
80
+ // Thinking about threads
81
+ DispatchQueue.main.async {
82
+ // Update UI on main thread
83
+ }
84
+
85
+ DispatchQueue.global(qos: .background).async {
86
+ // Heavy work on background thread
87
+ }
88
+ ```
89
+
90
+ ### New way (Swift Concurrency)
91
+
92
+ ```swift
93
+ // Thinking about isolation domains
94
+ @MainActor
95
+ func updateUI() {
96
+ // Runs on main actor (usually main thread)
97
+ }
98
+
99
+ func heavyWork() async {
100
+ // Runs on any available thread in pool
101
+ }
102
+ ```
103
+
104
+ ### Think in isolation domains
105
+
106
+ **Don't ask**: "What thread should this run on?"
107
+
108
+ **Ask**: "What isolation domain should own this work?"
109
+
110
+ - `@MainActor` for UI updates
111
+ - Custom actors for specific state
112
+ - Nonisolated for general async work
113
+
114
+ ### Provide hints, not commands
115
+
116
+ ```swift
117
+ Task(priority: .userInitiated) {
118
+ await doWork()
119
+ }
120
+ ```
121
+
122
+ You're describing the nature of work, not assigning threads. Swift optimizes execution.
123
+
124
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 7.2: Getting rid of the "Threading Mindset"](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
125
+
126
+ ## Suspension Points
127
+
128
+ ### What is a suspension point?
129
+
130
+ Moment where task **may** pause to allow other work. Marked by `await`.
131
+
132
+ ```swift
133
+ let data = await fetchData() // Potential suspension
134
+ ```
135
+
136
+ **Critical**: `await` marks *possible* suspension, not guaranteed. If operation completes synchronously, no suspension occurs.
137
+
138
+ ### Why suspension points matter
139
+
140
+ 1. **Code may pause unexpectedly** - resumes later, possibly different thread
141
+ 2. **State can change** - mutable state may be modified during suspension
142
+ 3. **Actor reentrancy** - other tasks can access actor during suspension
143
+
144
+ ### Actor reentrancy example
145
+
146
+ ```swift
147
+ actor BankAccount {
148
+ private var balance: Int = 0
149
+
150
+ func deposit(amount: Int) async {
151
+ balance += amount
152
+ print("Balance: \(balance)")
153
+
154
+ await logTransaction(amount) // ⚠️ Suspension point
155
+
156
+ balance += 10 // Bonus
157
+ print("After bonus: \(balance)")
158
+ }
159
+
160
+ func logTransaction(_ amount: Int) async {
161
+ try? await Task.sleep(for: .seconds(1))
162
+ }
163
+ }
164
+
165
+ // Two concurrent deposits
166
+ async let _ = account.deposit(amount: 100)
167
+ async let _ = account.deposit(amount: 100)
168
+
169
+ // Unexpected: 100 → 200 → 210 → 220
170
+ // Expected: 100 → 110 → 210 → 220
171
+ ```
172
+
173
+ **Why**: During `logTransaction`, second deposit runs, modifying balance before first completes.
174
+
175
+ ### Avoiding reentrancy bugs
176
+
177
+ **Complete actor work before suspending**:
178
+
179
+ ```swift
180
+ func deposit(amount: Int) async {
181
+ balance += amount
182
+ balance += 10 // Bonus applied first
183
+ print("Final balance: \(balance)")
184
+
185
+ await logTransaction(amount) // Suspend after state changes
186
+ }
187
+ ```
188
+
189
+ **Rule**: Don't mutate actor state after suspension points.
190
+
191
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 7.3: Understanding Task suspension points](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
192
+
193
+ ## Thread Execution Patterns
194
+
195
+ ### Default: Background threads
196
+
197
+ Tasks run on cooperative thread pool (background threads):
198
+
199
+ ```swift
200
+ Task {
201
+ print(Thread.current) // Background thread
202
+ }
203
+ ```
204
+
205
+ ### Main thread execution
206
+
207
+ Use `@MainActor` for main thread:
208
+
209
+ ```swift
210
+ @MainActor
211
+ func updateUI() {
212
+ Task {
213
+ print(Thread.current) // Main thread
214
+ }
215
+ }
216
+ ```
217
+
218
+ ### Inheritance example
219
+
220
+ ```swift
221
+ @MainActor
222
+ func updateUI() {
223
+ print("Main thread: \(Thread.current)")
224
+
225
+ await backgroundTask() // Switches to background
226
+
227
+ print("Back on main: \(Thread.current)") // Returns to main
228
+ }
229
+
230
+ func backgroundTask() async {
231
+ print("Background: \(Thread.current)")
232
+ }
233
+ ```
234
+
235
+ ## Swift 6.2 Changes
236
+
237
+ ### Nonisolated async functions (SE-461)
238
+
239
+ **Old behavior**: Nonisolated async functions always switch to background.
240
+
241
+ **New behavior**: Inherit caller's isolation by default.
242
+
243
+ ```swift
244
+ class NotSendable {
245
+ func performAsync() async {
246
+ print(Thread.current)
247
+ }
248
+ }
249
+
250
+ @MainActor
251
+ func caller() async {
252
+ let obj = NotSendable()
253
+ await obj.performAsync()
254
+ // Old: Background thread
255
+ // New: Main thread (inherits @MainActor)
256
+ }
257
+ ```
258
+
259
+ ### Enabling new behavior
260
+
261
+ In Xcode 16+:
262
+
263
+ ```swift
264
+ // Build setting or swift-settings
265
+ .enableUpcomingFeature("NonisolatedNonsendingByDefault")
266
+ ```
267
+
268
+ ### Opting out with @concurrent
269
+
270
+ Force function to switch away from caller's isolation:
271
+
272
+ ```swift
273
+ @concurrent
274
+ func performAsync() async {
275
+ print(Thread.current) // Always background
276
+ }
277
+ ```
278
+
279
+ ### nonisolated(nonsending)
280
+
281
+ Prevent sending non-Sendable values across isolation:
282
+
283
+ ```swift
284
+ nonisolated(nonsending) func storeTouch(...) async {
285
+ // Runs on caller's isolation, no value sending
286
+ }
287
+ ```
288
+
289
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 7.4: Dispatching to different threads using nonisolated(nonsending) and @concurrent (Updated for Swift 6.2)](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
290
+
291
+ **Use when**: Method doesn't need to switch isolation, avoiding Sendable requirements.
292
+
293
+ ## Default Isolation Domain (SE-466)
294
+
295
+ ### Configuring default isolation
296
+
297
+ **Build setting** (Xcode 16+):
298
+ - Default Actor Isolation: `MainActor` or `None`
299
+
300
+ **Swift Package**:
301
+
302
+ ```swift
303
+ .target(
304
+ name: "MyTarget",
305
+ swiftSettings: [
306
+ .defaultIsolation(MainActor.self)
307
+ ]
308
+ )
309
+ ```
310
+
311
+ ### Why change default?
312
+
313
+ Most app code runs on main thread. Setting `@MainActor` as default:
314
+ - Reduces false warnings
315
+ - Avoids "concurrency rabbit hole"
316
+ - Makes migration easier
317
+
318
+ ### Inference with @MainActor default
319
+
320
+ ```swift
321
+ // With @MainActor as default:
322
+
323
+ func f() {} // Inferred: @MainActor
324
+
325
+ class C {
326
+ init() {} // Inferred: @MainActor
327
+ static var value = 10 // Inferred: @MainActor
328
+ }
329
+
330
+ @MyActor
331
+ struct S {
332
+ func f() {} // Inferred: @MyActor (explicit override)
333
+ }
334
+
335
+ > **Course Deep Dive**: This topic is covered in detail in [Lesson 7.5: Controlling the default isolation domain (Updated for Swift 6.2)](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=lesson-reference)
336
+ ```
337
+
338
+ ### Per-module setting
339
+
340
+ Must opt in for each module/package. Not global across dependencies.
341
+
342
+ ### Backward compatibility
343
+
344
+ Opt-in only. Default remains `nonisolated` if not specified.
345
+
346
+ ## Debugging Thread Execution
347
+
348
+ ### Print current thread
349
+
350
+ **⚠️ Important**: `Thread.current` is unavailable in Swift 6 language mode from async contexts. The compiler error states: "Class property 'current' is unavailable from asynchronous contexts; Thread.current cannot be used from async contexts."
351
+
352
+ **Workaround** (Swift 6+ mode only):
353
+
354
+ ```swift
355
+ extension Thread {
356
+ public static var currentThread: Thread {
357
+ Thread.current
358
+ }
359
+ }
360
+
361
+ print("Thread: \(Thread.currentThread)")
362
+ ```
363
+
364
+ ### Debug navigator
365
+
366
+ 1. Set breakpoint in task
367
+ 2. Debug → Pause
368
+ 3. Check Debug Navigator for thread info
369
+
370
+ ### Verify main thread
371
+
372
+ ```swift
373
+ assert(Thread.isMainThread)
374
+ ```
375
+
376
+ ## Common Misconceptions
377
+
378
+ ### ❌ Each Task runs on new thread
379
+
380
+ **Wrong**. Tasks share limited thread pool, reuse threads.
381
+
382
+ ### ❌ await blocks the thread
383
+
384
+ **Wrong**. `await` suspends task without blocking thread. Other tasks can use the thread.
385
+
386
+ ### ❌ Task execution order is guaranteed
387
+
388
+ **Wrong**. Tasks execute based on system scheduling. Use `await` to enforce order.
389
+
390
+ ### ❌ Same task = same thread
391
+
392
+ **Wrong**. Task can resume on different thread after suspension.
393
+
394
+ ## Why Sendable Matters
395
+
396
+ Since tasks move between threads unpredictably:
397
+
398
+ ```swift
399
+ func example() async {
400
+ print("Thread 1: \(Thread.current)")
401
+
402
+ await someWork()
403
+
404
+ print("Thread 2: \(Thread.current)") // Different thread
405
+ }
406
+ ```
407
+
408
+ Values crossing suspension points may cross threads. **Sendable** ensures safety.
409
+
410
+ ## Best Practices
411
+
412
+ 1. **Stop thinking about threads** - think isolation domains
413
+ 2. **Trust the system** - Swift optimizes thread usage
414
+ 3. **Use @MainActor for UI** - clear, explicit main thread execution
415
+ 4. **Minimize suspension points in actors** - avoid reentrancy bugs
416
+ 5. **Complete state changes before suspending** - prevent inconsistent state
417
+ 6. **Use priorities as hints** - not guarantees
418
+ 7. **Make types Sendable** - safe across thread boundaries
419
+ 8. **Enable Swift 6.2 features** - easier migration, better defaults
420
+ 9. **Set default isolation for apps** - reduce false warnings
421
+ 10. **Don't force thread switching** - let Swift optimize
422
+
423
+ ## Migration Strategy
424
+
425
+ ### For new projects (Xcode 16+)
426
+
427
+ 1. Set default isolation to `@MainActor`
428
+ 2. Enable `NonisolatedNonsendingByDefault`
429
+ 3. Use `@concurrent` for explicit background work
430
+
431
+ ### For existing projects
432
+
433
+ 1. Gradually enable Swift 6 language mode
434
+ 2. Consider default isolation change
435
+ 3. Use `@concurrent` to maintain old behavior where needed
436
+ 4. Migrate module by module
437
+
438
+ ## Decision Tree
439
+
440
+ ```
441
+ Need to control execution?
442
+ ├─ UI updates? → @MainActor
443
+ ├─ Specific state isolation? → Custom actor
444
+ ├─ Background work? → Regular async (trust Swift)
445
+ └─ Need to force background? → @concurrent (Swift 6.2+)
446
+
447
+ Seeing Sendable warnings?
448
+ ├─ Can make type Sendable? → Add conformance
449
+ ├─ Same isolation OK? → nonisolated(nonsending)
450
+ └─ Need different isolation? → Make Sendable or refactor
451
+ ```
452
+
453
+ ## GCD to Isolation Domain Migration
454
+
455
+ Instead of asking "what thread should this run on?" ask "what isolation domain should own this work?"
456
+
457
+ - `DispatchQueue.main.async { }` → `@MainActor func updateUI()`
458
+ - `DispatchQueue.global().async { }` → `func work() async` (or `@concurrent` if it must leave caller isolation)
459
+ - `DispatchQueue(label:).sync { }` → `actor` or `Mutex` for protecting state
460
+ - Serial queue for ordering → `actor` (guarantees serial access)
461
+
462
+ ## Decision Rules
463
+
464
+ - UI state → usually `@MainActor`
465
+ - Mutable shared state → usually an `actor`
466
+ - Plain async work with no isolated state → `async` API with explicit ownership
467
+ - Work that must hop away from caller isolation under Swift 6.2-era behavior → consider `@concurrent`
468
+
469
+ ## Common Mistakes Agents Make
470
+
471
+ - Recommending GCD queue hopping when actor isolation already expresses the ownership model.
472
+ - Debugging correctness by thread ID instead of by isolation and ordering.
473
+ - Treating `await` as a blocking call — it suspends the task, freeing the thread.
474
+ - Mapping each `Task` to a conceptual thread.
475
+
476
+ ## Performance Insights
477
+
478
+ ### Why fewer threads = better performance
479
+
480
+ - **Less context switching**: CPU spends more time on actual work
481
+ - **Better cache utilization**: Threads stay on same cores longer
482
+ - **No thread explosion**: Predictable resource usage
483
+ - **Forward progress**: Threads never block, always productive
484
+
485
+ ### Cooperative pool advantages
486
+
487
+ - Matches hardware (one thread per core)
488
+ - Prevents oversubscription
489
+ - Efficient task scheduling
490
+ - Automatic load balancing
491
+
492
+ ## Further Learning
493
+
494
+ For migration strategies, real-world examples, and advanced threading patterns, see [Swift Concurrency Course](https://www.swiftconcurrencycourse.com).
495
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ivan Magda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.