How to solve: This application is modifying the autolayout engine from a background thread

后端 未结 1 966
日久生厌
日久生厌 2021-02-09 13:50

This error is logged to the console when some part of the code is changing UI items from other threads than the main thread. But how can I find where it does this?

相关标签:
1条回答
  • 2021-02-09 14:42

    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.

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