Main Thread checker

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

  1. Goto Product menu -> Scheme -> Edit Scheme
  2. Select Run (Debug) on the left side of the window
  3. Select Diagnostics (last tab)
  4. Under section “Runtime API checking” select — “Main Thread Checker”
  5. 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.

Common Causes

  1. Handing callbacks from a non-main thread. eg. URL request responses, App permissions requests, etc.
  2. Reading UIView or it’s properties from a background thread.