App debugging is an essential step in the application development process.
Still, there are some shortcuts to take and become better at iOS app debugging. Below, you will find a list of tips and tricks for iOS app debugging you can incorporate today to optimize your workflow and deliver quality iOS apps.
Check out more tips & tricks for iOS App Debugging:
LLDB is a very reliable and ultra-fast debugger. If you are using Xcode to write your iOS apps, there is no need to install it as it is a default debugger that comes pre-installed with Xcode. If you are using something else than Xcode, you can install LLDB by entering terminal and typing in “lldb.”
Using LLDB is very easy, and you can master it fast thanks to the abundant help documentation it comes with. To access LLDB help, type “help + command.” For instance, “help breakpoint” will show you how to use breakpoint syntax, which subcommands breakpoint support, and what each one of them does.
You can use “apropos” to look for specific terms in LLDB documentation. Consider it as a neat search function accessible via terminal. To use it, type in “apropos + phrase you are looking for.”
Po and p are few of the first commands iOS developers learn. Po is the command that prints object description, and p prints out the raw information about an object. V is the new command introduced in Xcode 10.2 that you can use instead of pos & p.
When used, p or v command will also create a local “$RX” (X will be a number in real use case scenario) variable, which is quite handy as it can be used for debugging.
Wouldn’t it be handy if you could stop program execution once one of the properties changes? You can set LLDB to stop and to do that only for some time every time a property you are interested in changes.
To keep tabs on the property or multiple properties at all times, you should start using Watchpoints. To do it, open the Debug Area and select the property you want to observe. You can see it in the left section of the debugger.
From this point on, the changes in the property will result in LLDB stopping.
While Xcode features several different breakpoints, here we will focus on Symbolic, Exception, and Swift Error breakpoints. These breakpoints can be set on symbols such as “viewDidLoad.” Breakpoints are quite useful to determine which function causes the bug to occur. If you set a symbolic breakpoint on the “viewDidLoad” function, Xcode will stop when the app calls the “viewDidLoad” function.
Creating symbolic breakpoints is easy:
● Click on the + button in the bottom left corner
● Click on Symbolic Breakpoint in the pop-up menu
To identify the very code line that’s responsible for the app crash, use Exception Breakpoint. It only triggers if an exception is thrown. On the other hand, you can use Swift Error Breakpoint to see all the errors you code throws.
If you are responsible for initial debugging as a developer, you can add debugging to your workflow without disrupting it at all. You can do this thanks to LLDB navigation actions:
● Step Over - This action will help you go to the next code line in the context, which is quite useful if you want to debug functions
● Step In - a neat action that will help you debug your code step by step. If you are in a position calling another function Step In will take you to the function without executing it
● Step Out - this action is great for checking whether the function works as intended or not. Xcode will stop once the function has returned
I hope our tips & tricks for iOS app debugging will be useful for you. What tips do you use?
With Love from Uptech!