Wednesday, April 20, 2011

Easy Way to Debug UIView Hierarchy

Do you want to see complete view hierarchy for debugging purposes? There is an easy way to do it, provided by Apple - totally unofficially!

Actually official documentation says it's undocumented and not supported. No problem with that. Very kind of Apple, good developer service!

Found this in Technical Note TN2239 "iOS Debugging Magic", section "Cocoa and Cocoa Touch - UIKit":
UIView implements a useful description method. In addition, it implements a recursiveDescription method that you can call to get a summary of an entire view hierarchy.
Therefore I could have saved lots of time and effort in How to Find MFMailComposeViewController Email Addresses with a single line of code. Just to verify that it's not possioble to find recipient email addresses by digging deep into view hierarchy I could have used this:
NSLog(@"%@", [controller.view recursiveDescription]);
Well, I did learn a lot. Both times.

No comments:

Post a Comment