I have had the benefit of a sneak preview into Rob and Mugunth’s upcoming book release -Â iOS 6 Programming Pushing the Limits: Advanced Application Development for Apple iPhone, iPad, and iPad Touch- which is an updated release to their successful iOS 5 pushing the limits series.
As any veteran programmers would know, one of the most important skills (among a multitude of skill requirements) to master is the art of debugging an application. Â Chapter 19 provides an excellent coverage of this topic in the context of iOS apps. Â Beginning with a conceptual introduction to LLDB (Apple’s Lower Level Debugger) and the difference from the older version of the debugger – GDB – the chapter introduces the intermediate programmer to the actual mechanics of debugging with LLDB and the use of breakpoints (which is no different from the use of breakpoints from many other advanced editors or debugging tools).
Having mucked around with almost 5 conceptually simple iOS apps, I am no strange to using breakpoints to zero in on problems. Â What is interesting, however, is the detailed explanation of different types of breakpoints – exception breakpoints, symbolic breakpoints. Â Of particular interest and of learning value to me personally, is the use of Ctrl-Click + “share” on the breakpoint to write a breakpoint state into a `xcshareddata` directory, which can be saved into git and so shared with a fellow developer.
Watchpoints are also interesting to me, being useful for specifically tracking data mutation events – particularly for global variables that have changed, in the context of Singleton implementations, Core Data persistent store coordinators or API engines.
Advanced Use of Debugger through Python Scripting
For our normal, simple use cases, introspecting objects at breakpoints is a simple matter of typing
po myObject po myDictionary po myArray
For scalar variables (e.g. integers or structs), we will of course use
p (int) self.myAge p (CGPoint) self.view.center
What if we need to search through a very large array containing a large number of objects? Â This is where we might have problems manually reading the 10,000 objects that are printed out. Â In such a case, we can actually use Python to run a search. Â Jumpt into the python shell prompt from the lldb prompt by typing “script”. Then, via the great example from the book:-
>>> import mypython_script >>> array Â = lldb.frame.FindVariable("myArray") >>> yes_or_no = mypython_script.search_object(array, "<search element>") Â Â # search_object is a method we write in our custom mypython_script .py file. >>> print yes_or_no
This nice little trick from the book goes straight into my personal bookmark.
The chapter ties up neatly with an explanation of how NSZombieEnabled flag/environment variable is used to track objects in memory, a summary of various types of Application crashes one commonly encounters and how crash stacks can be collected – “natively” via iTunes as well as on 3rd party services like TestFlight and HockeyApp.
All-in-all, this is a must-have book for any professional iOS developer and certainly a level-up for me. Â I have merely covered specifically this one chapter of a very detailed and extensive pro manual and I am certainly looking forward to grabbing a copy (or receiving a copy free ;-)) from Mugunth. Â Grab it at Amazon.com if you think this is something that would help you build even more awesome iOS apps -Â iOS 6 Programming Pushing the Limits: Advanced Application Development for Apple iPhone, iPad, and iPad Touch.