Does Not Compute, Part 2: Ambiguous Layout

A layout is ambiguous when there are not enough constraints for Auto Layout to determine the positions of all of the views. It is computationally expensive to determine whether a layout is ambiguous, so you will not see console output as with unsatisfiable constraints. However, Cocoa provides several tools for addressing ambiguous layout in the form of debugging APIs.

The most conspicuous tool is NSWindow’s visualizeConstraints(_:). When you call this method, Cocoa will decorate the window with visual representations of the constraints. This is shown in Figure 25.15.

Figure 25.15  Visualizing constraints on a window

If the layout is ambiguous, you will also see an Exercise ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.