在Xcode的debugging控制台输出中禁用自动布局约束错误消息

有没有办法(暂时)禁用自动布局错误/警告消息:

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. 

做了一些反编译,实际上有一个方法:

迅速

 NSUserDefaults.standardUserDefaults().setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable") 

Objective-C的

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

现在只会通知“_UIConstraintBasedLayoutLogUnsatisiableclosures”。

任何读者都必须提醒:这应该是最后的解决办法,关于debugging和修复约束问题的提示,请参阅WWDC的“自动布局之谜”会议: 第1 部分和第2部分 。

Swift 3.0解决scheme:

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

我试图解决这个使用lldb,我发现了一个解决scheme:

  1. 为模块UIKit中的符号UIViewAlertForUnsatisfiableConstraints创build一个符号断点。
  2. 作为断点动作添加debugging器命令“线程返回”
  3. 添加第二个debugging器命令:“c”
  4. 禁用“评估操作后自动继续”

如果您的应用程序遇到布局问题,则执行暂停。 使用指令“线程返回”,打印出错误的UIViewAlertForUnsatisfiableConstraints函数在警告消息打印到控制台之前被强制返回。

用“c”命令继续执行你的应用程序(注意:“评估操作后自动继续”在这种情况下不起作用)

然而,对于这些自动操作,如果连续点击两次,会导致您的应用程序崩溃,断点可能会performanceexception。 为了解决这个问题,可以在debugging器暂停程序的执行时删除断点操作并手动input命令。

对于任何想知道如何使用AppKit / Cocoa来做这个macOS / osx的人来说,

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