Disable autolayout constraint error messages in debug console output in Xcode

26,089

Solution 1

Did some decompiling and there's actually a way:

for Swift 5

UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")

Objective-C

[[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];

Now you'll only get notified that "_UIConstraintBasedLayoutLogUnsatisfiable is OFF".

Obligatory reminder for anyone reading this: this should be last resort, for tips on debugging and fixing constraint issues see WWDC's "Mysteries of Auto Layout" sessions: part 1 and part 2.

Solution 2

One more option is to temporarily put -_UIConstraintBasedLayoutLogUnsatisfiable NO (notice the dash) into Arguments Passed On Launch menu, under the Product -> Scheme -> Edit Scheme... -> Run -> Arguments tab (you can also open this menu by pressing ++<), like this:

enter image description here

Solution 3

Swift 4.0 & Swift 5.0 Solution:

// Hide Autolayout Warning
UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")

Swift 3.0 Solution:

// Hide Autolayout Warning
UserDefaults.standard.setValue(false, forKey:"_UIConstraintBasedLayoutLogUnsatisfiable")

Solution 4

for anyone who is wondering how to do this macOS / osx with AppKit/Cocoa

UserDefaults.standard.set(false, forKey: "NSConstraintBasedLayoutLogUnsatisfiable")
UserDefaults.standard.set(false, forKey: "__NSConstraintBasedLayoutLogUnsatisfiable")

Solution 5

I have tried to solve this using lldb and I found a solution:

  1. Create a Symbolic Breakpoint for the Symbol UIViewAlertForUnsatisfiableConstraints in the Module UIKit.
  2. As breakpoint action add the debugger command "thread return"
  3. Add a second debugger command: "c"
  4. Disable "Automatically continue after evaluating actions"

If your App encounters a layout issue, the execution is paused. With the instruction "thread return", the UIViewAlertForUnsatisfiableConstraints function which prints out the error is forced to return before the warning message is printed into the console.

With the "c" command the execution of your app is continued (Note: "Automatically continue after evaluating actions" does somehow not work in this case)

However with these automatic actions the breakpoint is likely to behave strangely if it gets hit two times in a row which will cause your app to crash. To solve this you can remove the breakpoint actions and enter the commands manually when the debugger pauses the execution of the program.

Share:
26,089
Markus Rautopuro
Author by

Markus Rautopuro

I'm an entrepreneur x N.

Updated on August 17, 2020

Comments

  • Markus Rautopuro
    Markus Rautopuro over 3 years

    Is there a way to (temporarily) disable autolayout error/warning messages:

    Unable to simultaneously satisfy constraints.
        Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
    (
        "<NSLayoutConstraint:0x170098420 H:[UIView:0x15c62c100(2)]>",
        "<NSLayoutConstraint:0x170098600 UIView:0x15c6294f0.leading == UIView:0x15c628d40.leadingMargin - 8>",
        "<NSLayoutConstraint:0x170098650 H:[UIView:0x15c6294f0]-(0)-[UIView:0x15c62b750]>",
        "<NSLayoutConstraint:0x1700986a0 UIView:0x15c62b750.width == UIView:0x15c6294f0.width>",
        "<NSLayoutConstraint:0x1700986f0 UIView:0x15c628d40.trailingMargin == UIView:0x15c62b750.trailing - 8>",
        "<NSLayoutConstraint:0x170098880 H:[UIView:0x15c6294f0]-(0)-[UIView:0x15c62c100]>",
        "<NSLayoutConstraint:0x1700988d0 UIView:0x15c628d40.centerX == UIView:0x15c62c100.centerX + 1>"
    )
    
    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0x170098420 H:[UIView:0x15c62c100(2)]>
    
    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
    The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
    
  • Markus Rautopuro
    Markus Rautopuro over 8 years
    Exactly - the need for me was to disable the errors temporarily so I could fix something else, and then return to the auto layout nightmare later. Thanks for this!
  • alex1511
    alex1511 about 7 years
    Great answer Witold! For those of you using Swift 3 : UserDefaults.standard.setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
  • Nike Kov
    Nike Kov almost 6 years
    Why add a new answer with duplication solution, when can edit an original answer.
  • Android teem
    Android teem over 5 years
    how and where to use that instruvtion
  • vbuzze
    vbuzze over 5 years
    @MarkusRautopuro where should we run this ?
  • vbuzze
    vbuzze over 5 years
    where should we run this ?
  • Charlton Provatas
    Charlton Provatas over 5 years
    i did at app entry point. If it's an app then you can do it in applicationDidFinishLaunching in your AppDelegate
  • Markus Rautopuro
    Markus Rautopuro over 5 years
    In the AppDelegate. You can do it in applicationDidFinishLaunching, for example.
  • Mike
    Mike almost 5 years
    Is there a way to enable that back? Setting the value to true doesn't work. I need that to be disabled for a short period of time
  • Sourabh Sharma
    Sourabh Sharma over 4 years
    @NikKov at that time.. I don't have access to edit that answer. As i remember.
  • rmvz3
    rmvz3 almost 4 years
    Great. I think this is the best solution to remove unwanted logs
  • djdance
    djdance over 3 years
    Actually I can't figure out what is "Target" here, so search for "Edit scheme" in drop-dow menu of App Scheme button, placed at the right of Play/Stop buttons on top of XCode
  • Jason Armstrong
    Jason Armstrong about 3 years
    Very helpful a few years later. It looks like Xcode 12.4 and iOS 14.3 with SwiftUI decided to become very chatty about Apple's own devs breaking constraints.
  • Xials
    Xials over 2 years
    I am using this for SwiftUI, so I put it in the init() method of the iOSApp struct.