Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The LLDB View Hierarchy Dump tip is something that I think I can use again and again and again.


It wasn't clearly explained in the blog post, but that .lldbinit command should be all on one line. It creates a new command, ”rd”, that can be used in two ways.

Typing “rd” by itself does “po [[UIApp keyWindow] recursiveDescription]”, so it dumps your entire on-screen view hierarchy.

Typing “rd someview” does “po [someview recursiveDescription]”, so it dumps the view hierarchy starting at a specific view.

For Mac (Cocoa) apps, the equivalent message is _subtreeDescription, but since a window is not a view, the entire-hierarchy command needs to be “po [[[NSApp frontWindow] contentView] _subtreeDescription]”.


I mentioned this to Mattt on Twitter but I don't think he saw it. There's a lot you can do at the debugger and recursiveDescription can be called on any UIView or UIView subclass. So if you set a breakpoint you can do something like:

    (lldb) po [self.view recursiveDescription]
from one of your view controllers to dump the hierarchy of that view. This of course will work on any object that is a subclass of UIView, such as a UITableView (subclass of UIScrollView, which is in turn a subclass of UIView), a UITableViewCell (directly inherited from UIView), etc.

There's a lot of good information provided by Apple on debugging here: http://developer.apple.com/library/ios/#technotes/tn2239/

It's definitely worth the time to go through it all if you spend any time debugging iOS code (and there's a Mac OS X equivalent but I can't speak for its usefulness).

I've also started writing a little piece on debugging code with lldb and Xcode, but it's a work in progress: https://gist.github.com/3943317


A good accompanying video from one of the XCode devs is the video from WWDC 2012 319 - Effective Debugging with Xcode 4


Definitely beats view.backgroundColor = [UIColor redColor];! Though I'm not sure I'll ever to shake that trusty old "debugging" hack.


I keep some UIColor categories around so at least I can have prettier colours for debugging. It would be nice to make a variant of the method that (somewhat randomly) colours all views and logs the usual info + the colour out to the console.


Well, I use the same method until I heard the DCIntrospect library (https://github.com/domesticcatsoftware/DCIntrospect)


It's super preliminary, but if you're debugging the problem I suspect you're debugging by looking at the view hierarchy (iOS touch handling), this might be helpful: https://github.com/MaxGabriel/debugiOSTouchHandling/blob/mas...


Yeah, I spotted that earlier today actually Max, I think it must have been something related to maintaining cocoapods. The library definitely has potential :)


This is also interesting (many might not know about it): https://github.com/glock45/iOS-Hierarchy-Viewer




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: