1

I have a large application that uses a number of third-party libraries and am now seeing the following error in the logs: "This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes."

From what I have found here on SO, this is probably being caused by a UI element being changed on a background thread, which is triggering the autolayout. Unfortunately, we have so many UI elements being changed by so many different moving parts that I do not know the best way to find the culprit.

Can anyone tell me how can I found out what exactly is triggering the autolayout change from a background thread?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kevin James Hunt
  • 333
  • 3
  • 11
  • Look in any completion block. Ensure any UI code in a completion block as wrapped in `DispatchQueue.main.async { }`. – rmaddy May 29 '17 at 17:21
  • This is a massive application. There are so many completion blocks. So, so many. I hoping there is some tools-based approach somewhere because otherwise it will take forever. – Kevin James Hunt May 31 '17 at 13:37
  • 2
    See https://stackoverflow.com/questions/32680303/ios9-this-application-is-modifying-the-autolayout-engine-from-a-background-thr and look at the last comment (the Swift link) of the accepted answer. – rmaddy May 31 '17 at 14:00
  • That might be just what I need! Thanks! – Kevin James Hunt Jul 19 '17 at 00:28

1 Answers1

1

Sometimes it's not a completion block, but anything that is performed in the background. In my case it was notifications that where sent. I implemented iCloud in my app, which means that when data was edited or added on another device, the other app(s) receive an iCloud update/notification, which triggered an update of the UITableView. The code to update the UITableView was not done in the MainThread. Adding the code as shown in the comments fixes it.