↓ Skip to main content

Video 10 min

How to Debug an iOS App in Xcode: Breakpoints, LLDB, Instruments and the Simulator

How to debug an iOS app in Xcode: conditional and symbolic breakpoints, the LLDB commands worth knowing, the view and memory debuggers, Instruments, the sanitizers, crash logs, and what the simulator misses that a real iPhone catches.

Narrated in English Subtitles: English, 日本語, 한국어, Tiếng Việt, 简体中文

Transcript

A tester tells me the app crashed. Not in my simulator. On their phone. So I ask them to plug it in, and I grab the console logs. There's often a system-level error sitting right there that explains the whole thing.

I spend way too much time debugging. Everyone does. And Xcode ships with debugging machinery that hardly anyone touches.

This is the workflow I've settled into over the years. The parts that actually save time.

Most people click the gutter to set a breakpoint and leave it at that. Right-click one, though, and there's a whole menu. A loop of a thousand items, and only one misbehaves? Give the breakpoint a condition, and it stops only on that one. Don't know where a method is being called from?

A symbolic breakpoint pauses on every single call. This should be the first thing you set up in any new project. It pauses the moment something throws, not after the app has already died. It's caught more nil-unwrapping bugs for me than I'd like to admit. And breakpoints don't have to stop at all.

They can print a value, or play a sound, and carry on. A logger that never interrupts you.

Hit a breakpoint, and the console at the bottom is LLDB. It's genuinely useful. The command po prints objects in a readable format. That's 90 percent of my LLDB usage, right there. But this is where LLDB earns its keep.

Change a variable, or call a method, without recompiling. Try the fix, and continue. From the same prompt, I walk the call stack and step through the code line by line. And a watchpoint pauses whenever a value changes, wherever it happens. Gold for tracking down unexpected state mutations.

Xcode's console is fine, until you need to see everything. System logs, crash reports, the lot. That's when I open Console.app. Log with OSLog, and it's structured, fast, redacts sensitive data, and survives crashes. print is fine for throwaway checks.

Anything you'll want later belongs in OSLog. Proper predicate queries narrow it down to just the failures, or just the last five minutes. And logs export straight into bug reports. When the UI is broken and you can't see why, the view debugger explodes the whole hierarchy into 3D. Rotate it, and things jump out.

Invisible buttons swallowing taps. And once, an image that was accidentally ten thousand pixels wide. Purple warnings mean constraints are fighting. Give them identifiers, and the log actually becomes readable. The simulator has time-savers of its own, and most of them sit in its Debug menu.

Slow Animations runs everything at one tenth speed, so you can see what's actually happening during a transition. A simulated memory warning has found me plenty of image caching bugs. Everything works fine, until it fires, and suddenly all your images vanish. Network Link Conditioner reproduces the request that worked fine on WiFi, but timed out on cellular. Status bar overrides fake the time and battery level, for consistent screenshots.

And simulated locations take you anywhere without leaving your desk, for bugs that only show up in certain regions.

Then there's memory. The memory graph shows every object, and the part you actually care about: which ones are leaking. Click a leak and you see the retain cycle. The most common one I see: a closure capturing self strongly. The fix is weak self.

And delegates need to be weak too. For serious investigation, there's Instruments. Memory that grows linearly over time is probably a leak. When the app is slow, the Time Profiler shows where the time is actually going. I once found a JSON parsing function being called a thousand times a second.

Moved it to a background queue, and the UI stopped stuttering. And Xcode automatically catches UI updates made on background threads. The fix is hopping back to the main queue.

Then there's a row of checkboxes in the scheme that catch bugs you'd never find by hand. Address Sanitizer finds memory corruption. It makes the app two to three times slower, but catches bugs that are near impossible to find any other way. Thread Sanitizer catches data races. You can't run both at once, so when a crash is being weird, I alternate.

Zombie Objects tells you exactly when you're touching freed memory. Just don't leave it on. Memory climbs forever.

Some scenarios keep coming back. A crash on launch? An exception breakpoint usually catches it. If not, suspect missing Info.plist keys, force-unwrapped optionals, or dependency injection failing. UI not updating?

Every. Single. Time. Wrong thread, a disconnected outlet, or a view that isn't in the hierarchy. Memory warnings crashing the app?

Usually it's images never released from a cache, or a retain cycle. Mysterious crashes? Intermittent usually means threading, so Thread Sanitizer. Crashing inside system frameworks usually means memory corruption, so Address Sanitizer. When the crash happened on someone else's phone, the report usually still exists.

In Xcode's Organizer, or on the device itself. My app ships over-the-air updates, and the simulator is the easiest place to debug that whole flow. I watch the manifest requests, make the network bad on purpose, and check the server on its own before digging into the client. Outside Xcode, a proxy shows all your network traffic, and lets you test error conditions. Proxyman has a nicer UI than Charles.

I switched last year, and haven't looked back. And Reveal works like the view debugger on physical devices, without Xcode attached.

Most of my debugging happens in the simulator, because it's quick. But it runs on your Mac's processor, memory and network. And some bugs only exist on a phone. Real speed, real memory limits, real networks. So I build and debug logic in the simulator.

Before a release, I run the app on the oldest iPhone I still support. Performance, memory pressure and anything that touches hardware haven't really been tested until they've run on a device. A free Apple ID is enough to sign for your own phone. Since iOS sixteen, it also needs Developer Mode turned on. Plug it in once, tick connect via network, and it stays in Xcode over WiFi.

And the device console shows everything. That's why I ask testers to plug their phones in. When something breaks, here's what I actually do. Exception breakpoint. Reproduce the bug.

A breakpoint nearby. Check values with po, and change them to test fixes. Then work backwards from the symptom. Crash? Exception breakpoint.

Slow? Time Profiler. Memory? Instruments. Weird UI?

View debugger. Things I wish I'd known earlier. Use assertions. Commit before you start debugging. And learn LLDB properly.

It's faster than rebuilding your app twenty times. And bugs that only appear on device are almost always threading or memory. Or performance. I keep Xcode, Console.app and Proxyman open, and Instruments when things get serious. No single tool covers everything.

The view debugger won't find a memory leak. Instruments won't untangle an Auto Layout conflict. So most of the skill is matching the tool to the symptom. That part just comes with repetition. After enough retain cycles, you start to smell them from the stack trace alone.

Debugging never becomes fun, exactly. But it does stop being miserable. The full post, with every command and setting, is on jared.lynskey.co.nz.

More videos

Claude Code Worktrees: Running Parallel Agents Without Collisions

Cloudflare 520, nginx 499 and Postgres Stalls: Keeping Webhooks Alive

pytest-testmon: Run Only the Tests Affected by Your Code Change

Replacing My Self-Hosted Expo Update Server with Codemagic Patch