Main Thread Checker is used to detect invalid use of AppKit, UIKit, and other APIs from a background thread. Updating UI on a thread other than the main thread is a very common mistake. It can result in missed UI updates, visual defects, data corruptions, and crashes.
Main Thread Checker is automatically enabled in your app starting Xcode 9.
How it works
Main Thread Checker dynamically replaces the implementations of methods that should only be called on the main thread with a version that prepends the check. Methods known to be safe for use on background threads are excluded from this check.
Do it yourself
- Goto Product menu -> Scheme -> Edit Scheme
- Selecr Run (Debug) on left side of the window
- Select Diagnostics (last tab)
- Under section "Runtime API checking" select - "Main Thread Checker"
- You can also select "Pause on issues". This will pause your debugger whenever a violation occurs and help you in understanding issue early and with better debug information.
Handing callbacks from a non-main thread. eg.
- URL request responses
- App permissions requests
Reading UIView or it's properties from a background thread.
Image source: https://i.stack.imgur.com/XwEf1.jpg