Last Updated: February 25, 2016
·
650
· supremegravity

Inspect UIViewController hierarchies from REPL via sugarcube

Via sugarcube you can inspect and access the UIViewController hierarchy at runtime:

First include this mixin
(main)> include SugarCube::Adjust

Then
(main)> tree


 0: . UIWindow(#c0a4db0, [[0.0, 0.0], [320.0, 480.0]])
 1: -- UIView
 2: +-- UIView
 3: +-- UIView
 4:-- UIView
 5: -- UILayoutContainerView
 6: +-- UINavigationTransitionView
 7: |-- UIViewControllerWrapperView
 8: | -- UIView
 9: |-- UILabel(..., text: "Center Panel")
 10: -- UINavigationBar
 11: +-- _UINavigationBarBackgroun
 12: |-- UIImageView
 13: +-- UINavigationItemView
 14: -- UINavigationButton
 15: +-- UIImageView
 16: +-- UIImageView
 17:-- UIButtonLabel
</code></pre>



After running tree, $sugarcube_items contains an array of items in the tree, indexed as indicated in the printout:

center_panel_label = $sugarcube_items[9]