[iOS] This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.
使用xcode7 後一陣子發現在某些情況,之前專案會中斷在一行code 上
選了繼續後出現
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.
原因是使用XCode7 iOS9+ 會認定這行可能會有crash 的風險,所以停下來警告
原因是這段code 是UI 畫面更新,但你呼叫的是非主線程
所以只要讓回主線程在執行就可以了
Swift
dispatch_async(dispatch_get_main_queue(), { // code here })
Objective-C
dispatch_async(dispatch_get_main_queue(), ^{ // code here });
不错,不错,看看了!
That’s the peefrct insight in a thread like this.
看看!
怎麼加了還是會出現這段This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.警告
http://stackoverflow.com/questions/28302019/getting-a-this-application-is-modifying-the-autolayout-engine-error
// Move to a background thread to do some long running work
DispatchQueue.global(qos: .userInitiated).async {
// Bounce back to the main thread to update the UI
DispatchQueue.main.async {
self.friendLabel.text = “You are following \(friendCount) accounts”
}
}
感謝提供