Avatar ·

Error «This application is modifying the autolayout engine from a background thread» — how to fix?

Hello everyone! I'm a beginner in Swift and macOS development. I encountered a strange error that doesn't always appear, but only when the application performs some long operation. The console outputs the message: ``` 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. ``` I have a simple example: I load data from the internet on a background thread, and after completion I want to update `NSTextField` on the screen. Here is my code: ```swift import Cocoa class ViewController: NSViewController { @IBOutlet weak var statusLabel: NSTextField! override func viewDidLoad() { super.viewDidLoad() // Emulate long loading DispatchQueue.global().async { self.loadData() } } func loadData() { // Simulate loading Thread.sleep(forTimeInterval: 2.0) let result = "Data