Getting a “This application is modifying the autolayout engine from a background thread” error?

后端 未结 21 1643
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 15:52

Been encountering this error a lot in my OS X using swift:

\"This application is modifying the autolayout engine from a background thread, which can

相关标签:
21条回答
  • 2020-11-22 16:39

    You must not change the UI offside the main thread! UIKit is not thread safe, so that above problem and also some other weird problems will arise if you do that. The app can even crash.

    So, to do the UIKit operations, you need to define block and let it be executed on the main queue: such as,

    NSOperationQueue.mainQueue().addOperationWithBlock {
    
    }
    
    0 讨论(0)
  • 2020-11-22 16:40

    If you want to hunt this error, use the main thread checker pause on issues checkbox. Fixing it is easy most of the times, dispatching the problematic line in the main queue.

    0 讨论(0)
  • 2020-11-22 16:41

    I had the same issue when trying to update error message in UILabel in the same ViewController (it takes a little while to update data when trying to do that with normal coding). I used DispatchQueue in Swift 3 Xcode 8 and it works.

    0 讨论(0)
提交回复
热议问题