在我的OS X中使用swift遇到了很多这个错误:

“这个应用程序正在从后台线程修改自动布局引擎,这可能会导致引擎损坏和奇怪的崩溃。这将在未来的版本中导致异常。”

我有一个NSWindow我将视图交换到窗口的contentView。当我尝试执行NSApp时会得到错误。或者当我向窗口添加子视图时。尝试禁用自动调整大小的东西,我没有任何使用自动布局的东西。任何想法吗?

有时它很好,什么都没有发生,其他时候它完全破坏了我的UI,什么都没有加载


当前回答

我有同样的问题时,试图更新错误消息在UILabel在同一个ViewController(它需要一点时间来更新数据时,试图这样做的正常编码)。我在Swift 3 Xcode 8中使用了DispatchQueue,它可以工作。

其他回答

我也有同样的问题。结果我使用的是需要主队列的UIAlerts。但是,他们已经被弃用了。 当我将UIAlerts更改为UIAlertController时,我不再有这个问题,也不必使用任何dispatch_async代码。教训是,注意警告。他们会在你意想不到的时候帮助你。

我在使用TouchID时遇到了这个问题,如果这对其他人有帮助,包装你的成功逻辑,它可能在主队列中对UI有作用。

当我在一个NSURLConnection异步请求完成处理程序中调用一个做UI更新的块时,我有这个问题,因为更新到iOS 9 SDK。使用dispatch_main_queue将块调用放在dispatch_async中解决了这个问题。

它在iOS 8中运行良好。

对我来说,这个错误消息来自Admob SDK的一个横幅。

我可以通过设置一个条件断点来跟踪原点到“WebThread”。

然后我就可以通过封装Banner的创建来摆脱这个问题:

dispatch_async(dispatch_get_main_queue(), ^{
   _bannerForTableFooter = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
   ...
}

我不知道为什么这有帮助,因为我看不出这段代码是如何从一个非主线程调用的。

希望它能帮助到任何人。

I also encountered this problem, seeing a ton of these messages and stack traces being printed in the output, when I resized the window to a smaller size than its initial value. Spending a long time figuring out the problem, I thought I'd share the rather simple solution. I had once enabled Can Draw Concurrently on an NSTextView through IB. That tells AppKit that it can call the view's draw(_:) method from another thread. After disabling it, I no longer got any error messages. I didn't experience any problems before updating to macOS 10.14 Beta, but at the same time, I also started modifying the code to perform work with the text view.