47

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?

Monolo
  • 18,205
  • 17
  • 69
  • 103
Yoav
  • 5,962
  • 5
  • 39
  • 61
  • Does anyone have an updated answer for Xcode 7/Swift 2? – Matt Oct 13 '15 at 02:45
  • @Matt : Xcode 7 / Swift 2: NSUserDefaults.standardUserDefaults().setBool(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints") – nspire Oct 16 '15 at 12:09

5 Answers5

61

You can configure the setting for a particular scheme as follows ...

1) Select the scheme from the popup menu and choose Edit Scheme ...

Edit Scheme ... menu

2) In the following slide down window add a new entry to Arguments Passed on Launch.
Copy and paste the following line.

-NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES

Edit view

brynbodayle
  • 6,546
  • 2
  • 33
  • 49
JJD
  • 50,076
  • 60
  • 203
  • 339
  • @Matt Sorry. I can not - I do no longer work with Xcode / Objective-C. – JJD Oct 28 '15 at 08:21
  • I can also confirm this works in Xcode 8 — Make sure to include the leading "-" at the beginning of the argument. – ElmerCat Sep 28 '16 at 16:43
50

You may also set

Objective C:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"];

Swift <3:

NSUserDefaults.standardUserDefaults().setBool(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints")

Swift 3-4.2 (at least):

UserDefaults.standard.set(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints")

in applicationDidFinishLaunching.

Note that this will set it for both yourself and your end-users, which may not be what you want (don't go into production like this!). You can set it only for yourself by setting the -NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES argument in your "Debug" run scheme (described in a separate answer).

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
maxbareis
  • 886
  • 9
  • 17
  • 2
    They aught to mention in the log message that the key is a magic NSString and not a defined constant. Or they aught to actually define it as a constant. – ArtOfWarfare Nov 14 '13 at 20:33
  • 3
    Swift: `NSUserDefaults.standardUserDefaults().setBool(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints")` – User Apr 06 '15 at 17:17
  • 1
    Use ...setInteger(1,... instead – Alex Jun 16 '16 at 08:01
9

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.

Monolo
  • 18,205
  • 17
  • 69
  • 103
6

Swift 3.0

UserDefaults.standard.set(true, forKey: "NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraint‌​s")
Barath
  • 1,656
  • 19
  • 19
1

Just add it as an argument when running the app from the command line or in the scheme settings at Xcode.

Yoav
  • 5,962
  • 5
  • 39
  • 61