• 未分類
  • 6

[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
});

Comments

comments

您可能也會喜歡…

6 個回應

  1. zengda表示:

    不错,不错,看看了!

  2. Alan_yo表示:

    怎麼加了還是會出現這段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.警告

  3. SL表示:

    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”
    }
    }

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料