1 min read

Fix mysterious Auto Layout warnings

If you're using Auto Layout daily like me, I'm sure sometime you'll come across mysterious warnings starting with this:

[LayoutConstraints] Unable to simultaneously satisfy constraints.
  Probably at least one of the constraints in the following list is one you don't want. 
  Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 

Sometimes it's your fault, so go fixing the layout issues. But sometimes Xcode console just prints those lengthy warnings while everything is working well. It's pretty annoying.

For example, this warning I came across:

    "<NSLayoutConstraint:0x60400028d980 UIView:0x7f94ec58a840.height == 1>",
    "<NSLayoutConstraint:0x60400028dbb0 UITableViewCellContentView:0x7f94ec58a640.bottom == UIView:0x7f94ec58a840.bottom>",
    "<NSLayoutConstraint:0x60400028dc50 UIView:0x7f94ec58a840.top == UITableViewCellContentView:0x7f94ec58a640.top + 30>",
    "<NSLayoutConstraint:0x60800028bfe0 UITableViewCellContentView:0x7f94ec58a640.height == 44>"

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60400028d980 UIView:0x7f94ec58a840.height == 1>

It seems a height constraint which was set internally by UIKit caused a conflict with my constraints. What can I do?

After searching high and low, I found one neat trick to fix this issue: set a constraint’s priority to 999 so that Xcode stop complaining. In this case I changed the bottom constraint’s priority and Xcode finally shut up.