Search code examples
cocoansuserdefaultsautolayout

How to set NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints?


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?


Solution

  • 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).