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

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

    The "this application is modifying the autolayout engine from a background thread" error is logged in the console long after the actual problem occured, so debugging this can be hard without using a breakpoint.

    I used @markussvensson's answer to detect my problem and found it using this Symbolic Breakpoint (Debug > Breakpoints > Create Symbolic Breakpoint):

    1. Symbols: [UIView layoutIfNeeded] or [UIView updateConstraintsIfNeeded]
    2. Condition: !(BOOL)[NSThread isMainThread]

    Build and run the app on the emulator and replicate the steps that lead to the error message being thrown (the app will be slower than usual!). Xcode will then stop the app and mark the line of code (e.g. the call of a func) that's accessing the UI from a background thread.

提交回复
热议问题