I’ve been trying to tame the AutoLayout beast recently, and wanted to be able to see where my various views where ending up. I started to write a NSView subclass that dumped out a printable grid in the drawRect: method when I stumbled across a neat technique that works out of the box.

Using the following command, I can get all the NSView objects to draw a border around themselves in a different colour:

defaults write com.logdiver.LogDiver NSShowAllViews YES

Note that in the example above, the setting applies to my application that has a bundle identifier of com.logdiver.LogDiver

The result of this is a UI that looks something like:

Neat, huh?

Update

This will render problematic constraints and allow you to click on them to dump the constraint settings to the console. For example, in the following example I have set two height constraints (one is 22 and the other is 27) on the NSTextField for the Name field.

When I click on the orange constraint arrow, the following gets emitted to the console: