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

后端 未结 21 1647
爱一瞬间的悲伤
爱一瞬间的悲伤 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:26

    It needs to be placed inside a different thread that allows the UI to update as soon as execution of thread function completes:

    Modern Swift:

    DispatchQueue.main.async {
        // Update UI
    }
    

    Older versions of Swift, pre Swift 3.

    dispatch_async(dispatch_get_main_queue(){
        // code here
    })
    

    Objective-C:

    dispatch_async(dispatch_get_main_queue(), ^{
        // code here
    });
    

提交回复
热议问题