Debugging Auto Layout: Unsatisfiable Contraints

When we work with auto layout we will hit an unsatisfiable constraint error at some point. The result is a view that looks somehow broken and there are a lot of text in the Xcode’s debugger window.

The unsatisfiable constraint error means that there are some conflicting constraints and the layout engine cannot solve our layout. The engine then breaks some of the constraints to make the layout possible.

The log tells us which constraints the layout engine did break. It also lists all the constraints related to the error. Reading the log can be a bit tedious, but there are few things that we can do to make debugging easier.

First, we can assign identifiers for our constraints.

These identifiers are printed out in the error log making it easier to recognise the constraints.

Another thing is that we can limit the log output to only vertical or horizontal axis. Print out the constraints for any given view using the LLDB command:

po imageView constraintsAffectingLayout(for: )