sugarcube v0.4

Two days, two minor version bumps! That means two new features, worthy of such bumpage. Sweet.

Sugarcube::Adjust::tree

I'm pretty sure you've been wanting this.

If you don't know about the Sugarcube::Adjust module, please read about it.

sugarcube v0.4 has the tree command. pass it a view (self, if you cmd+click a view) and it will do what you might hope it would. :-)

Ooooh, this is pretty cool, and it'll get cooler as I add appropriate inspect methods to UIView classes (UILabels show their label, UITextFields show their value, etc).

# I have cmd-clicked a view, and I just happen to know how far up the UIWindow object is:
({UITableView @ x: 0.0 y:0.0, 3...)> tree superview.superview.superview.superview.superview.superview.superview.superview
  0: . {UIWindow @ x: 0.0 y:0.0, 320.0×480.0}
  1: `-- {UIView @ x: 0.0 y:0.0, 320.0×480.0} child of UIWindow
  2:     `-- {FabTabView @ x: 0.0 y:0.0, 320.0×480.0} child of UIView
  3:         +-- {UIView @ x: 0.0 y:0.0, 320.0×431.0} child of FabTabView
  4:         |   `-- {UILayoutContainerView @ x: 0.0 y:0.0, 320.0×480.0} child of UIView
  5:         |       +-- {UINavigationTransitionView @ x: 0.0 y:0.0, 320.0×480.0} child of UILayoutContainerView
  6:         |       |   `-- {UIViewControllerWrapperView @ x: 0.0 y:64.0, 320.0×416.0} child of UINavigationTransitionView
  7:         |       |       `-- {UIView @ x: 0.0 y:0.0, 320.0×416.0} child of UIViewControllerWrapperView
  8:         |       |           `-- {UITableView @ x: 0.0 y:0.0, 320.0×368.0} child of UIView
  9:         |       |               +-- {TeamTableCell @ x: 0.0 y:104.0, 320.0×52.0} child of UITableView
 10:         |       |               |   +-- {UIImageView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
 11:         |       |               |   `-- {UITableViewCellContentView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
 12:         |       |               |       +-- {UILabel @ x: 11.0 y:7.0, 245.0×20.0} child of UITableViewCellContentView
 13:         |       |               |       +-- {UILabel @ x: 11.0 y:21.0, 245.0×30.0} child of UITableViewCellContentView
 14:         |       |               |       `-- {UIImageView @ x: 241.0 y:-1.0, 82.5×56.0} child of UITableViewCellContentView
 15:         |       |               +-- {TeamTableCell @ x: 0.0 y:52.0, 320.0×52.0} child of UITableView
 16:         |       |               |   +-- {UIImageView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
 17:         |       |               |   `-- {UITableViewCellContentView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
 18:         |       |               |       +-- {UILabel @ x: 11.0 y:7.0, 245.0×20.0} child of UITableViewCellContentView
 19:         |       |               |       +-- {UILabel @ x: 11.0 y:21.0, 245.0×30.0} child of UITableViewCellContentView
 20:         |       |               |       `-- {UIImageView @ x: 241.0 y:-1.0, 82.5×56.0} child of UITableViewCellContentView
 21:         |       |               +-- {TeamTableCell @ x: 0.0 y:0.0, 320.0×52.0} child of UITableView
 22:         |       |               |   +-- {UIImageView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
 23:         |       |               |   `-- {UITableViewCellContentView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
 24:         |       |               |       +-- {UILabel @ x: 11.0 y:7.0, 245.0×20.0} child of UITableViewCellContentView
 25:         |       |               |       +-- {UILabel @ x: 11.0 y:21.0, 245.0×30.0} child of UITableViewCellContentView
 26:         |       |               |       `-- {UIImageView @ x: 241.0 y:-1.0, 82.5×56.0} child of UITableViewCellContentView
 27:         |       |               +-- {UIImageView @ x: 0.0 y:361.0, 320.0×7.0} child of UITableView
 28:         |       |               `-- {UIImageView @ x: 313.0 y:212.0, 7.0×156.0} child of UITableView
 29:         |       `-- {UINavigationBar @ x: 0.0 y:20.0, 320.0×44.0} child of UILayoutContainerView
 30:         |           +-- {UINavigationBarBackground @ x: 0.0 y:0.0, 320.0×47.5} child of UINavigationBar
 31:         |           +-- {UINavigationItemView @ x: 160.0 y:21.0, 0.0×0.0} child of UINavigationBar
 32:         |           +-- {UINavigationButton @ x: 5.0 y:7.0, 50.0×30.0} child of UINavigationBar
 33:         |           |   +-- {UIImageView @ x: 0.0 y:0.0, 50.0×30.0} child of UINavigationButton
 34:         |           |   `-- {UIButtonLabel @ x: 13.0 y:7.0, 23.0×15.0} child of UINavigationButton
 35:         |           `-- {UINavigationButton @ x: 282.0 y:7.0, 33.0×30.0} child of UINavigationBar
 36:         |               +-- {UIImageView @ x: 0.0 y:0.0, 33.0×30.0} child of UINavigationButton
 37:         |               +-- {UIImageView @ x: 10.0 y:7.0, 13.0×14.0} child of UINavigationButton
 38:         |               `-- {UIButtonLabel @ x: 0.0 y:0.0, 0.0×0.0} child of UINavigationButton
 39:         `-- {UIView @ x: 0.0 y:424.0, 320.0×56.0} child of FabTabView
 40:             +-- {UIButton @ x: 0.0 y:7.0, 64.0×49.0} child of UIView
 41:             |   `-- {UIImageView @ x: 0.0 y:0.0, 64.0×49.0} child of UIButton
 42:             +-- {UIButton @ x: 64.0 y:7.0, 64.0×49.0} child of UIView
 43:             |   `-- {UIImageView @ x: 0.0 y:0.0, 64.0×49.0} child of UIButton
 44:             +-- {UIButton @ x: 128.0 y:0.0, 65.0×56.0} child of UIView
 45:             |   `-- {UIImageView @ x: 0.0 y:0.0, 65.0×56.0} child of UIButton
 46:             +-- {UIButton @ x: 193.0 y:7.0, 63.0×49.0} child of UIView
 47:             |   `-- {UIImageView @ x: 0.0 y:0.0, 63.0×49.0} child of UIButton
 48:             `-- {UIButton @ x: 256.0 y:7.0, 64.0×49.0} child of UIView
 49:                 `-- {UIImageView @ x: 0.0 y:0.0, 64.0×49.0} child of UIButton
=> {UIWindow @ x: 0.0 y:0.0, 320.0×480.0}

You can then use assign to pick one of those views by index:

({UITableView @ x: 0.0 y:0.0, 3...)> assign 32
=> {UINavigationButton @ x: 5.0 y:7.0, 50.0×30.0} child of UINavigationBar

But know what? Typing superview.superview.superview...superview is annoying. Running tree by itself will find the UIWindow object, and use that.

> tree
0: . {UIWindow @ x: 0.0 y:0.0, 320.0×480.0}
1:     `-- {UIView @ x: 0.0 y:0.0, 320.0×480.0} child of UIWindow
...

This uses UIApplication.sharedApplication.keyWindow, so if you haven't called makeKeyAndVisible, it won't work. This should never happen if you are using this in the REPL like you should be, but there it is.

However, if you have assigned an object to assign already, tree uses that INSTEAD OF UIWindow.

> assign self.superview
> tree
0. . {TeamTableCell @ x: 0.0 y:52.0, 320.0×52.0} child of UITableView
1. +-- {UIImageView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
2. `-- {UITableViewCellContentView @ x: 0.0 y:0.0, 320.0×52.0} child of TeamTableCell
3.     +-- {UILabel @ x: 11.0 y:7.0, 245.0×20.0} child of UITableViewCellContentView
4.     +-- {UILabel @ x: 11.0 y:21.0, 245.0×30.0} child of UITableViewCellContentView
5.     `-- {UIImageView @ x: 241.0 y:-1.0, 82.5×56.0} child of UITableViewCellContentView
> assign 5
=> {UIImageView @ x: 241.0 y:-1.0, 82.5×56.0}

I'm already REALLY loving this - I hope you do, too!

sugarcube v0.3, btw.

This was mentioned as part of teacup v0.3 yesterday. It introduces some factory methods to create UIButtons and UITableView. UIButton.custom is especially useful - that is the button type if you're going to use an image.

See yesterday's announcement for more info on all that.