Apple added a private helper _printHierarchy
in iOS8 that can be used in LLDB console:
po [[[UIWindow keyWindow] rootViewController] _printHierarchy]
which prints out the whole view controller hierarchy in text form.
This works only if you are debugging code on Objective C. In Swift, however, this doesn't work:
(lldb) po [[[UIWindow keyWindow] rootViewController] _printHierarchy]
error: <EXPR>:1:13: error: expected ',' separator
[[[UIWindow keyWindow] rootViewController] _printHierarchy]
^
,
<EXPR>:1:24: error: expected ',' separator
[[[UIWindow keyWindow] rootViewController] _printHierarchy]
^
,
<EXPR>:1:44: error: expected ',' separator
[[[UIWindow keyWindow] rootViewController] _printHierarchy]
^
,
An equivalent usage in Swift doesn't work either:
po UIApplication.sharedApplication().keyWindow!.rootViewController!._printHierarchy
ends up with an error (probably because _printHierarchy
is a private property):
(lldb) po UIApplication.sharedApplication().keyWindow!.rootViewController!._printHierarchy()
error: <EXPR>:1:64: error: 'UIViewController' does not have a member named '_printHierarchy'
UIApplication.sharedApplication().keyWindow!.rootViewController!._printHierarchy
^ ~~~~~~~~~~~~~~~
The question is: How to print out the view controller hierarchy in Swift? Or is there a way how to use ObjC in LLDB console even in Swift projects?