2

I use auto layout in almost every views of my application. But once in a while my debug console shows we weird warning. My application seems to work fine despite these error. Here is how these warning looks like. First example Example 1 second example Example 2

Making symbolic breakpoints seems help find what the issues are. but how and where do i make them also how do i fix these issues once i find them

Nikesh Hyanju
  • 140
  • 3
  • 16
  • 1
    "Making symbolic breakpoints seems to solve these problem" They won't solve anything. They will "block" your app when debugging letting you the time to debug and fix your issue. See the doc: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/debugging_tools.html#//apple_ref/doc/uid/TP40015022-CH8-SW2 – Larme Feb 02 '18 at 09:59
  • https://stackoverflow.com/questions/26389273/how-to-trap-on-uiviewalertforunsatisfiableconstraints – Andrey Gershengoren Feb 02 '18 at 10:07
  • Symbolic breakpoints are a debugging tool, just like any other breakpoint is. IMHO something that is at least as helpful is learning to read this kind of console output. (1) It explains which constraint is being broken - example #1 is a `UIImageView` width and #2 a `UIButton` height. (2) Sometimes the next question should be "does the layout look correct?" –  Feb 02 '18 at 10:43
  • (3) Sometimes it's more easy to tell which constraint is conflicting. In example #2 I'd look at the constraints listed second and third - it suggests that the button height is 23 points from the top and 17 points from the bottom. The fourth constraint suggests that the superview is set to a height of 59. If so, it implies that the button is 59-40 or 19 points. So the layout engine is conflicted between 19 and 19.5, and with no priorities set it decided to break the 19.5 constraint. (And yes, example #1 is more difficult to figure out - making it a good candidate for deeper debugging. –  Feb 02 '18 at 10:46
  • i am getting you @dfd but then what if i have multiple UIButton or multiple UIImageView in my View how do i find which particular button or image is causing issue ? – Nikesh Hyanju Feb 02 '18 at 10:48
  • "Deeper debugging." :-) For me that usually means trail and error. (1) I usually code my constraints in code, so sometimes the *type* of constraint means I stupidly forgot to set the auto resizing mask to `false`. (2) Sometimes the listed constraints use VFL and from there you can infer which button it is - it will list things from top to bottom or left to right. (3) If all else fails, I know that commenting out constraints - or deleting them in IB - will result in unwanted behavior like moving the button to the top left of the root view. (4) At the very worst, I lay out each thing one-by-one. –  Feb 02 '18 at 10:54

2 Answers2

1

"Making symbolic breakpoints seems to solve these problem" is incorrect. Making a symbolic breakpoint will not magically fix the issue. It will break code execution when it reaches that condition, or in this case, when you get one of these unsatisfiable constraints.

You can enable these by selecting the breakpoints tab and then select the plus menu and select symbolic link

enter image description here

And then add the symbolic breakpoint mentioned

enter image description here

These errors/warning are saying that you have conflicting constraints (rules) in your view. auto layout will basically pick one and drop the other. so 'most' of the time it shouldn't cause too much of an issue. To resolve them you need to see which rules are conflicting with each other and either remove one, make your view constraints more specific to not cause the issue, adjust priorities of certain constraints.

Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • updated the answer. you would need to provide the details of the view, the constraint warning you are getting and details of all constraints on that view for me to guide you on a particular one – Scriptable Feb 02 '18 at 10:32
  • 1
    You need to understand the error message. There are contradictory constraints, and the OS will break one in attempt to fix the issue. But nothing can guaranty that it will break the correct one. Find the one causing the issue, disable it, or change it according to your needs. – Larme Feb 02 '18 at 10:40
0

In your first example, like the debugger said you need to work on UIImageView's width as it is causing to break the constriant.

Similarly work upon the UIButton's height in second example. These are the only ones causing issues.

Give it a try.

Parion
  • 428
  • 9
  • 18