iOS Debugging Skills
In the film Taken, Liam Neeson has a particular set of skills. Using said skills, Neeson deftly resolves his one major blocker (a kidnapped daughter). In like manner - minus the mayhem - a software developer's debugging skills pay off in the field - thus, the worthy developer will value what enhances his debugging powers.
Dancing in the Debugger covers potent debugging skills for the LLDB command line; the good stuff appears about 3/4 into the article.
To summarize: Have you ever wanted to pause your running iOS app in Xcode to manipulate and better understand all the visual elements on screen, or conveniently change variable values and see results without stopping, recompiling, and running the app again?
Chisel is the Bruce-Lee's-nun-chucks-compliment to your LLDB bug-fu. Some fine Facebook folk are sharing their commonly used LLDB debugging commands in the form of python scripts so that you can type (in the LLDB debugger command line)...
"po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]”
...to see your app’s current UI hierarchical tree print to the console!
Or, let’s say I have just run the above command and printed this big hierarchical list of UI elements. Instead of sorting through this big dump of objects for a UISegmentedControl I can just type...
(lldb) fv segmented
Now just grab that address and go to town…
e id $mySegmentedControl = (id)0x7fd72ac3ba90
That just created the convenience variable $mySegmentedControl. Here is the current control:
Let's change a color...
(lldb) e (void)[$mySegmentedControl setBackgroundColor:(UIColor *)[UIColor redColor]]
...the background color changed to red without even resuming in the debugger!
A single tear runs down your cheek. Try it out! Just read the article and install Chisel - you’ll be glad you did.
By the way, to grab those controller images just above, all I did was type:
(lldb) visualize $mySegmentedControl
The Preview app opens up showing your snapshot of the object. BOOM!