Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable autolayout constraint error messages in debug console output in Xcode

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.
like image 400
Markus Rautopuro Avatar asked Jul 06 '15 07:07

Markus Rautopuro


People also ask

What is Autolayout Swift?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.

What is Os_activity_mode?

OS_ACTIVITY_MODE=disable. info, debug, disable. Sets the logging mode of the launched process to the specified level.


3 Answers

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.

like image 66
Witold Skibniewski Avatar answered Oct 19 '22 11:10

Witold Skibniewski


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

like image 40
danylokos Avatar answered Oct 19 '22 11:10

danylokos


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")
like image 26
Sourabh Sharma Avatar answered Oct 19 '22 10:10

Sourabh Sharma