Main Thread Checker and Hangs
Detecting UI work on background threads and resolving main-thread hangs.
Main Thread Checker
The Main Thread Checker (MTC) is a Xcode diagnostic that reports UIKit/AppKit API calls made from background threads at runtime.
// Enabled by default in Xcode Debug scheme:
// Product → Scheme → Edit → Diagnostics → ☑ Main Thread Checker
// Violating calls log a purple runtime warning in XcodeCommon MTC Violations
Updating UI from completion handlers or background queues are the most frequent violations.
URLSession.shared.dataTask(with: url) { data, _, _ in
self.label.text = "Done" // VIOLATION: background thread
}.resume()
// Fix:
DispatchQueue.main.async { self.label.text = "Done" }