Disable autolayout constraint error messages in debug console output in Xcode

前端 未结 5 1548
清酒与你
清酒与你 2020-12-04 07:07

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

Unable to simultaneously satisfy constraints.
    Probably at least one of the con         


        
相关标签:
5条回答
  • 2020-12-04 07:12

    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")
    
    0 讨论(0)
  • 2020-12-04 07:12

    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")
    
    0 讨论(0)
  • 2020-12-04 07:24

    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.

    0 讨论(0)
  • 2020-12-04 07:24

    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:

    0 讨论(0)
  • 2020-12-04 07:31

    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.

    0 讨论(0)
提交回复
热议问题