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

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

    Main problem with "This application is modifying the autolayout engine from a background thread" is that it seem to be logged a long time after the actual problem occurs, this can make it very hard to troubleshoot.

    I managed to solve the issue by creating three symbolic breakpoints.

    Debug > Breakpoints > Create Symbolic Breakpoint...

    Breakpoint 1:

    • Symbol: -[UIView setNeedsLayout]

    • Condition: !(BOOL)[NSThread isMainThread]

    Breakpoint 2:

    • Symbol: -[UIView layoutIfNeeded]

    • Condition: !(BOOL)[NSThread isMainThread]

    Breakpoint 3:

    • Symbol: -[UIView updateConstraintsIfNeeded]

    • Condition: !(BOOL)[NSThread isMainThread]

    With these breakpoints, you can easily get a break on the actual line where you incorrectly call UI methods on non-main thread.

提交回复
热议问题