Reading crashes and fixing bugs with AI
A repeatable method for turning a scary crash log into a fixed bug, using AI as a diagnostic partner.
Every app crashes during development. The skill isn't avoiding crashes — it's reading them calmly. AI is excellent at interpreting crash logs if you give it the right slice of information.
The debugging loop
- Reproduce — find the exact tap sequence that triggers it. A bug you can reproduce is a bug you can fix.
- Read the top of the stack — Xcode highlights the line that crashed and prints a reason in the console. Read the first meaningful line, not the whole wall of text.
- Isolate — note the file, line, and the values involved (Xcode's debugger shows variables).
- Ask precisely — give AI the error, the crashing function, and what you were doing.
The most common Swift crash
// Console: "Fatal error: Unexpectedly found nil while unwrapping an Optional value"
let title = entry.aiTitle! // <- the "!" forces an optional; crashes when it's nilThe ! says "I promise this is never nil." When that promise is false — an entry without insights yet — the app dies. The fix is to handle the nil case honestly:
let title = entry.aiTitle ?? "Untitled" // provide a fallback instead of crashingMy iOS app crashes with "Fatal error: Unexpectedly found nil while unwrapping an Optional" on this line: [paste line]. Here's the function: [paste]. Explain why it's nil in plain terms and give me the safe version. Don't just add another force-unwrap.
The last sentence matters — without it, models sometimes 'fix' a crash by hiding it. Steer toward the honest fix.
Copy the actual console text. 'It crashed when I tapped save' gives the model nothing; the real error string plus the function usually gets a correct fix on the first try.