6.10 · Threads and run loops, observers, and what actually runs in a custom mode
The run loop questions you already know say what a loop is. These four show what it does when nobody drives it, when you watch it, and when you invent a mode.
Mental model. A run loop is a loop you must be running. On a thread you made it does nothing until you attach a source and call run; on the main thread it is the heartbeat that observers, timers and the main dispatch queue all hang from.
Loops you run yourself
Per-thread loops, observer activities and the main queue across modes.
- Why does a Timer created on a background thread never fire, and when does a thread’s run loop return immediately?
Every thread can have a run loop, created lazily the first time you ask for RunLoop.current, but it is not running until you call run. A Timer only registers… - What are run loop observers, in which order do they fire, and what do frameworks use them for?
A CFRunLoopObserver is a callback attached to a loop for chosen activities: entry, before timers, before sources, before waiting, after waiting and exit. The… - Which work still runs while the run loop is in a tracking or custom mode, and what does “common modes” really contain?
Q217 explains why a default-mode Timer stalls during scrolling. The complete picture is a table of what is registered for which mode. The check runs the main…
More in iOS platform internals
- 6.1 · The process, the sandbox, entitlements and privacy prompts
- 6.2 · App and scene lifecycle in UIKit and SwiftUI
- 6.3 · The run loop, its modes, and the main-thread contract
- 6.4 · The launch path: dyld, initialisers and the first frame
- 6.5 · Background modes, BGTaskScheduler and background transfers
- 6.6 · Memory warnings, jetsam and the watchdog
- 6.7 · Info.plist, URL schemes, universal links and associated domains
- 6.8 · App groups, keychain groups and extensions as separate processes
- 6.9 · How a process dies, what it costs, what confines it and what seals it
- 6.11 · Launch arguments, the scene callbacks, and reading a binary and its plists