While working on PSPDFKit, I more and more embrace viewController containment to better distribute responsibilities between different view controllers.
One thing that always annoyed me about that is that
po [[UIWindow keyWindow] recursiveDescription] is less and less useful if you just see a big bunch of UIView’s.
I asked some engineers at WWDC if there’s something like recursiveDescription, just for UIViewControllers, but they didn’t had a answer on that, so I finally wrote my own.
Regular output of
po [[UIWindow keyWindow] recursiveDescription]
The solution is surprisingly simple. Add the following code somewhere to your project and you’re done. As a bonus, this also lists attached childViewControllers if you run iOS5 or above, and it will show you if a childViewController has a greater frame than it’s parentViewController (this is usually a easy to miss bug).
Note the usage of
__attribute__((constructor)), this will call the method at a very early stage on app loading. (thus we need an explicit @autorelease pool).
Works with or without ARC, iOS 4.3 and above. (
imp_implementationWithBlock requires iOS 4.3, unless you want to perform some dark magic.)
For those if you that are curious, I use a private API call (
_viewDelegate), but that’s obfuscated (it would pass a AppStore review) and you really only should compile that function in DEBUG mode anyway.