We all love the good old trusty ‘print()’ statement but Xcode is a powerful IDE with many amazing advanced debugging tools that can help you in numerous ways!
In this post I will show you the ones that a successful mobile developer should be familiar with.
1. Simulate Background Fetch
You can find this option under Xcode -> Debug -> Simulator Background Fetch, this tool is powerful one to have when debugging iOS apps that make use of the background fetch API, this makes it possible to manually trigger an operation that’s otherwise being done by the operating systems, in a production environment.
2. Quick Look
when hitting a breakpoint, this button will allow you to visualise the selected in-memory instances of your classes . This can mean different things for different classes. For example, you can view the real image that’s being stored into an UIImage object (just like in the following photo). Read Apple’s official documentation for more information on the Quick Look debugging tool.
3. Generic Breakpoints
You can use them to pause the execution of the application right before an exception is being thrown out or a test case fails. Another powerful debugging technique. Have a look at Apple’s official documentation, to learn more about generic breakpoints.
4. Advanced Breakpoints
Breakpoints can be used for more in-depth actions than simply breaking into a method and pausing the execution at a specific line to inspect the current application state. You can try editing a breakpoint and view the wide variety of options available for use. Xcode supports conditional breakpoints, sets the number of times before stopping for each breakpoint as well as takes specific actions when an advanced breakpoint gets hit, such as logging, running a shell command, an Apple Script or even playing a sound. Tremendously useful, especially when debugging multithreaded environments or methods that are being called frequently (such as layoutSubviews, for example). To find out more, check out this guide for how to use breakpoints in Xcode.
5. View Hierarchy Debugger
This tool provides you with a way to visualise your views and the UI hierarchy. You can rotate the screen, select any view, view children as well as the name of their view classes. You can also inspect the auto layout constraints or find the memory address of the objects underlying the views. For a detailed explanation of how to debug views in Xcode, have a look at this tutorial.
6. Debug Navigator
The debug navigator in Xcode has a set of valuable debugging tools. In addition to displaying how much memory, network, CPU and disk your current app instance is using, it has an interactive call stack navigator, listing all the threads and grand central dispatch queues currently running in your app’s sandbox, together with their current call stack. You can click on each method’s signature and inspect the object graph and app state context at each step of the execution. This is amazing for debugging code as well as ramp up on large codebases since it shows exactly where all the methods are being called from and in what order.
7. Location Simulator
Next to the “Debug View Hierarchy” button, there’s a “Simulate location” feature, that will allow you to simulate any locations you want to test your app at. Use this to insure your app behaves properly in any location.
8. Debugging Slow Animations
This is more of an iOS Simulator debugging trick, but it’s effective for iOS apps when debugging animations. It does what the name implies: slows down the execution of the UI animations so that they can be observed with human eyes. In this way, you can notice any glitches in your animations and you’ll be able to find out when and why they occurred.
9. Color Blended Layers
If you’re debugging layout performance for your iOS mobile app, you should turn on “Color Blended Layers” options on your simulator. This feature will highlight in a red color which areas of your UI layout takes a lot of time to render, and therefore affect performance. Things like blurring effects or unwise opacity settings can affect the performance of your app. Ideally, all the highlighted layers should be green on the entire screen.
10. LLDB Advanced Debugging
A complete command language, powering a sublime debugging experience for experienced developers. You can basically run complex commands directly on the objects that exist in the current app’s sandbox. More information in Apple’s documentation on using LLDB. The community also recommends using Chisel, which is rich open source set of LLDB commands.