I am getting the following message from Cocoa Auto Layout mechanism:
Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens.
But I don't know how to "Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES".
How do I set this?
You may also set
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"];
in ApplicationDidFinishLaunching.
You can configure the setting for a particular scheme as follows ...
1) Select the scheme from the popup menu and choose Edit Scheme ...
2) In the following slide down window add a new entry to Arguments Passed on Launch.
Copy and paste the following line.
-NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES
Lots of good suggestions in previous answers, but they all have to be repeated for each app you develop, even for quick one-offs to try out an idea.
If you want it to be on by default for all apps and all users, you can set it in your defaults database by typing the following command into Terminal:
defaults write -globalDomain NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES
You can check the man page for variations on the theme, for instance if you want it to be more restricted in scope.
One disadvantage of keeping this setting around is that other people's software suddenly gets highlighted for ambiguous layouts - even on occasion stuff from Apple itself.
You may therefore want to turn it off again for periods. The command for that is pretty straight forward:
defaults write -globalDomain NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints NO
And just to be clear: the setting, when typed into Terminal, applies only to the machine in question, so end users will not get the setting. This also means that beta testers will not see the purple shadow, which may or may not be what you want.
Swift 3.0
UserDefaults.standard.set(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints")
Just add it as an argument when running the app from the command line or in the scheme settings at Xcode.