定位 This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread This can lead to engine corruption and weird crashes 如何捕捉这个错误的代码
要捕捉这个错误,您可以使用以下代码:
DispatchQueue.main.async {
// 在主线程中访问和修改自动布局引擎的代码
}
DispatchQueue.global().async {
// 在后台线程中访问和修改自动布局引擎的代码
}
在上面的代码中,您可以在主线程中访问和修改自动布局引擎的代码,并将需要在后台线程中访问和修改自动布局引擎的代码放在全局队列中。
这样做是为了确保在访问和修改自动布局引擎之前,先在主线程中进行访问。这样可以避免在后台线程中直接访问和修改自动布局引擎而导致的错误和崩溃。
请注意,这只是一种捕捉错误的方法。在实际情况中,您可能需要根据自己的应用程序结构和需求进行适当调整。
原文地址: https://www.cveoy.top/t/topic/i9df 著作权归作者所有。请勿转载和采集!