Rule Swift

Main Thread UI

All UI updates must happen on the main thread

swiftconcurrencyuimacosiosappkit
CLAUDE.md

All UI updates must be dispatched to the main thread. AppKit and UIKit will crash or behave unpredictably if views are mutated from background threads.

// From a background callback
URLSession.shared.dataTask(with: url) { data, _, _ in
    DispatchQueue.main.async {
        self.label.stringValue = "Done"
        self.progressBar.isHidden = true
    }
}.resume()

In async/await code, use @MainActor on methods that touch UI:

@MainActor
func updateProgress(_ value: Double) {
    progressBar.doubleValue = value
}

Copy this block into your CLAUDE.md or agent config file to enforce it in your workflow.

get crystl