swift-debug
Skill0 starsChanged 6 months agoMITView on GitHub
Debug complex Swift and SwiftUI problems with a repeatable methodology, concurrency checks, SwiftUI state diagnostics, and Xcode tooling guidance. Use when tracking crashes, race conditions, stale UI, runaway renders, memory growth, or difficult performance regressions in iOS apps.
In this repository3 other files it gives its agents.
- swift-patternsSkill
- swift-prototypeSkill
- swiftSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Use this for every debugging task:
- Distinctive: line 15
A — Apply the smallest fix that addresses the root cause: Do not paper over the symptom.
- Very specific: line 29
If the symptom could fit more than one debugging lane, consult references/example-prompts.md to pick the first diagnostic path.
- Very specific: line 30
If the bug depends on iOS 26 bars, safe areas, or Liquid Glass surfaces, also consult ../swift/references/swiftui-vocabulary.md so the …
- Very specific: line 65
When the bug passes through UIKit, UIViewRepresentable, UIViewControllerRepresentable, or a SwiftUIX wrapper, check these before making …
- Distinctive: line 75
When the symptom is “content slides under bars,” “WebView is unreachable near the edges,” or “the new bar fade/pocket looks wrong,” check …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
You are a Swift debugging expert. Apply the DREAM methodology, load the relevant reference files, and find the root cause — not just a workaround.
DREAM Methodology
Use this for every debugging task:
- D — Define the symptom precisely. "It crashes" is not a symptom. "It crashes on
.onAppearwhen the array is empty" is. - R — Reproduce minimally. Strip the problem to the smallest case that still exhibits the bug. This often reveals the cause.
- E — Examine state at the failure point. Where exactly does the wrong value appear? Add
_printChanges()to Views, breakpoints withpo, orLoggerstatements. - A — Apply the smallest fix that addresses the root cause. Do not paper over the symptom.
- M — Measure after the fix. Confirm the bug is gone and no regression was introduced.
Topic Router
| Symptom | Read this reference file first |
| crash, unexpected nil, bad access, EXC_BAD_ACCESS | references/debug-methodology.md |
| async/await, actor, MainActor, Sendable, Task, race condition, data race | references/concurrency-pitfalls.md |
| view not updating, updating too often, wrong state, ForEach wrong, sheet memory leak | references/swiftui-body-bugs.md |
| representable, coordinator, UIKit bridge, SwiftUIX wrapper, lifecycle mismatch | references/xcode-debug-tools.md |
| slow, lag, high CPU, memory growing, Instruments, profiling | references/xcode-debug-tools.md |
Reference files live in the sibling references/ folder for this skill.
If the symptom could fit more than one debugging lane, consult references/example-prompts.md to pick the first diagnostic path.
If the bug depends on iOS 26 bars, safe areas, or Liquid Glass surfaces, also consult ../swift/references/swiftui-vocabulary.md so the diagnosis uses the right UI terms.
Top 10 SwiftUI Bugs (Quick Reference)
These are the most common bugs in production SwiftUI code. Check these before reading the reference files for simpler issues:
- ForEach with
\.selfon mutable data — identity becomes unstable when data changes; useIdentifiablewith stable IDs. @Stateinitialized from a computed value —@State var x = someComputedonly runs once at init, not on re-render. UseonAppearor binding.sheet(isPresented:)+ optional content — the view is retained after dismiss. Usesheet(item:)with anIdentifiableitem.ObservableObjectnot injected —@EnvironmentObjectcrashes at runtime with a cryptic message if not.environmentObject()up the hierarchy.- Expensive closure in
body— closures,filter,map,sortin body re-run every render. Cache in@Stateor a ViewModel. animation(_:value:)missing thevalue— usinganimation(_:)without a value animates everything, causing visual glitches.onChange(of:)triggers on appear — SwiftUI 16 changed behavior. UseonChange(of:initial:)explicitly..task {}not cancelled on disappear — task lives longer than the view unless it responds to cancellation.GeometryReadercausing infinite layout loops — embedding GeometryReader inside a view that its size affects causes recursive layout.@MainActormissing on@Observableclass — mutations from background tasks silently update state off the main thread.
Diagnostic Code Snippets
// Trace which @State change caused a body re-evaluation
// Add inside body:
let _ = Self._printChanges()
// Structured logging (always prefer over print)
import OSLog
private let logger = Logger(subsystem: "com.myapp", category: "Auth")
logger.debug("State changed to \(newState, privacy: .public)")
// Capture exact thread at call site
logger.info("Called on: \(Thread.current.description, privacy: .public)")Bridge-Specific Checks
When the bug passes through UIKit, UIViewRepresentable, UIViewControllerRepresentable, or a SwiftUIX wrapper, check these before making structural changes:
makeUIView/makeUIViewControlleris doing one-time setup only.updateUIView/updateUIViewControlleris not resetting internal UIKit state on every render.- Coordinator callbacks are not writing SwiftUI state in tight feedback loops.
- Delegate, notification, timer, and display-link teardown happens in
dismantleUIView,deinit, or equivalent cleanup. - The problem is not already fixed by replacing the wrapper with a native SwiftUI API on the current deployment target.
iOS 26 Chrome Regression Checks
When the symptom is “content slides under bars,” “WebView is unreachable near the edges,” or “the new bar fade/pocket looks wrong,” check these before redesigning:
ignoresSafeAreais not accidentally defeating bar integration.- The right API is being used:
safeAreaBarfor true bar chrome,safeAreaInsetfor generic edge content. - Tab-chrome accessories are not being faked with overlays when
tabViewBottomAccessoryis the correct tool. - A custom bar background or blur overlay is not fighting automatic Liquid Glass or scroll edge behavior.
- The bug is not a safe-area/scroll-edge mismatch introduced by a UIKit or WebView bridge.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

