Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8. Constraint referencing items turned off in current configuration

I've faced with the problem after updating to Xcode 8. Every time after UI objects are deleted from the main storyboard I get the following warning:

Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.

enter image description here

It looks like this is an Xcode bug, but anyway I want to remove these warnings from the project. I found that there were the same problem with Xcode 6 here but no answer from that question fix the problem right no. So when I find the incorrect constraint in the storyboard and delete it the amount of incorrect constrains is increasing instead of decreasing. I things that I've also tried:

  • cleaned the project
  • cleaned the derived data
  • deleted all constraints and added new ones from the scratch

Any ideas?

like image 489
Danny Avatar asked Oct 15 '16 09:10

Danny


4 Answers

I was having several views that were not Installed, after updating to xcode 8.1, I had 2 warnings.

Following steps worked for me:

1) Clean the project and restart Xcode, warnings decreased to 1.

2) Selecting the warning will show exactly which constraint having an issue. Open Attributes Inspector and select those views where constraint is applied, look for Installed if its unchecked on the view (not on constraint). You can either select Installed on the view, or unselect Installed on constraint itself.

See screenshot below. Installed was unchecked on view, not on the constraint that the warning was pointing to :)

Installed is unchecked on a view, not on constraint itself

Update: Same issue again with another ViewController, a UIView was not Installed for a size class, I unselect Installed on constraint itself and warning is gone too, I guess its not an Xcode bug, its claiming to turn Installed on/off on both UIView and Constrarint

like image 118
AamirR Avatar answered Nov 03 '22 01:11

AamirR


The short answer: Inspect the source code for your storyboard for each of the ids in your warnings by searching 'id="theIdFromWarning". The ids are for the constraints. When you find the constraint id, it will reference the two element ids. Search for the elements by searching 'id="theIdForElement"' Then you'll find the name or some piece of info in that element source code to find out what element you're looking at. Then switch the storyboard back from source code to the interface builder, find the two elements, and see which size class the related constraint is installed but the element isn't. Example: ViewA.right could be horizontally constrained to ViewB.left, installed on all size classes, but ViewA might only be installed on height=Regular size class. Solution: Install ViewA on all size classes, or uninstall the constraint on all size classes and add the constraint to only the height=Regular size class.

Longer answer, step-by-step:

I was not able to easily see what constraints/elements these warnings were referring to. For me, I was able to right click the warning, and select "Reveal in log". This revealed 10 warnings in this style format:

/my/filepath/to/storyboard:1xe-xx-Bx5: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.

If your log doesn't show a detailed description like this, then right-click on any log reference to Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration. warning and select Expand all transcripts, then search your log file for the constraint descriptions.

So, I opened my storyboard, right clicked the storyboard file in the project navigator and selected 'view as source code' searched for every constraint by the listed id (in the above example, I searched for the id:1xe-xx-Bx5), and found one reference to it:

<constraint firstItem="Mwb-6O-DKs" firstAttribute="top" secondItem="y2M-Sk-Ygh" secondAttribute="bottom" constant="19" id="1ce-xx-Bx5"/>

What this tells me is:

  • That the constraint has an id of 1ce-xx-Bx5
  • The constraint is associated with two elements:
  • One has the id of Mwb-6O-DKs
  • The other has the id of y2M-Sk-Ygh

So I searched the source code for the first element by id, by searching for id="Mwb-6O-DKs" and found this:

<label ...(truncating for readability sake)...text="Build Label"...(truncating for readability sake)...id="Mwb-6O-DKs">

This tells me that the first element is a UILabel with the title 'Build Label'.

Searching for the second element by id, id="y2M-Sk-Ygh", revealed:

<viewController storyboardIdentifier="login"...(truncating for readability sake)...<layoutGuides><viewControllerLayoutGuide type="top" id="y2M-Sk-Ygh"/>

So I take this to mean that the UILabel with the text "Build Label" has a top constraint that is turned off. (since the viewControllerLayoutGuide constraint should never be turned off, it must be the UILabel.

Lo and behold, it was not installed. I selected the Installed checkbox for the UILabel, and the error disappeared.

1 down, 9 more to go! (F*ing Xcode...)

like image 44
jungledev Avatar answered Nov 03 '22 01:11

jungledev


Show the Report Navigator [That is the rightmost tab on the leftmost column]. This will show build log with constraint ids. For further details, look into this stackoverflow's post.

like image 4
Munahil Avatar answered Nov 03 '22 01:11

Munahil


Reason

You have an item (i.e. view) which is un-Installed, but, it has constraints which are still installed. (commented by fattie)

How to find out specific constraint

It is difficult to find exact constraint which causes this warning. It mentioned step by step in BastiBen's answer how to find out the specific constraint.

Solution

  • Check both the items/views(first & second ) of the specific constraint whether any item is un-Install for any specific size-class. In my case the constraint was installed for all size-classes, but one of the item was installed for "wC hR" (Ref following image). enter image description here
  • Install the item to resolve the warning.
  • Now, build the app, if you still find the same warning for that specific interface/XIB file, don't worry this time some other constraints have the same problem.

Advice for Future

  • Please check whether views are properly installed while copy/paste them from other interfaces.
like image 4
Milan Kamilya Avatar answered Nov 03 '22 01:11

Milan Kamilya