Debugging UIViewAlertForUnsatisfiableConstraints

Karthikkeyan Bala Sundaram
3 min readApr 18, 2018

As an app developer in iOS platform, I often ran into constraint warnings like below,

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.("<NSLayoutConstraint:0x600000292660 UIView:0x7f94ff5b3890.leading == UILayoutGuide:0x6000001bf720'UIViewSafeAreaLayoutGuide'.leading   (active)>","<NSLayoutConstraint:0x600000292750 UILayoutGuide:0x6000001bf720'UIViewSafeAreaLayoutGuide'.trailing == UIView:0x7f94ff5b3a80.trailing   (active)>","<NSLayoutConstraint:0x600000292930 H:[UIView:0x7f94ff5b3890]-(0)-[UIView:0x7f94ff5b3a80]   (active)>","<NSLayoutConstraint:0x600000292980 UIView:0x7f94ff5b3890.width == 375   (active)>","<NSLayoutConstraint:0x604000095400 'UIView-Encapsulated-Layout-Width' UIView:0x7f94ff5b3c70.width == 320   (active)>","<NSLayoutConstraint:0x6000002924d0 'UIViewSafeAreaLayoutGuide-left' H:|-(0)-[UILayoutGuide:0x6000001bf720'UIViewSafeAreaLayoutGuide'](LTR)   (active, names: '|':UIView:0x7f94ff5b3c70 )>","<NSLayoutConstraint:0x6000002925c0 'UIViewSafeAreaLayoutGuide-right' H:[UILayoutGuide:0x6000001bf720'UIViewSafeAreaLayoutGuide']-(0)-|(LTR)   (active, names: '|':UIView:0x7f94ff5b3c70 )>")Will attempt to recover by breaking constraint<NSLayoutConstraint:0x600000292980 UIView:0x7f94ff5b3890.width == 375   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.

When I see such issue we immediately set a symbolic breakpoint with UIViewAlertForUnsatisfiableConstraints. When I run the app again to reproduce the issue Xcode will stop at the above constraint warning.

What to do now with pointers and assembly codes?

After some research, I found some solution to debug this breakpoint. If you see the above image you can see strings like %rbp, %rsp, %rbx, %r15 & etc. These properties holds the address of view(s) and constraint(s), those are the reason behind the constraint issue. We could print them in Xcode console to see more details about that.

I usually start by printing rbx, because it, usually in my experience, is NSArray, which contains all the views and constraints those are involved in the issue.

Open your Xcode console and execute the below command.

po $rbx

The above result looks exactly like what the warning message, so, what can we do with it. Three thinks to remember here,

  • The program execution stopped at the breakpoint
  • You have the memory addresses of all the views those involved in the constraint issues.
  • LLDB lets your evaluate obj-c expression at runtime

If you check the result of po $rbx command, you can see the memory addresses of view. e.g. UIView: 0x7f94ff5b3c70

I usually chance the appearance of the some views and continue the program execution.

Execute the below command in the Xcode console, using the memory addresses you got from your previous print command.

ex [(UIView *)0x7f94ff5b3890 setBackgroundColor: [UIColor greenColor]]ex [(UIView *)0x7f94ff5b3c70 setBackgroundColor: [UIColor greenColor]]

Now hit Continue program execution button to run the app. Now you will see two views one in red color and another in green color in your screen.

Now you know which views potential causes constraint issue. If everything is fine with the views then repeat the steps with different views till you find the issue.

Some time the views you changed the colors might be buried under other views, so it wont be immediately visible on the screen. In such case you could use Debug View Hierarchy to dig deeper in to your view hierarchy.

In the snapshot of views hierarchy, you can clear all the top level views till you see your “colored” views,

Hope this article helps. Leave a comment if there are any doubts.

Sorry for the poor grammar

--

--