As far as I understand, the main thread has a run loop.
When an iOS app launches, the process must keep the run loop running to stay alive.
Does that mean the main thread is the very first thread created when the process starts?
[is] the main thread … the very first thread created when the process starts?
Yes. When the system starts a process, it creates within that process a single thread that is, by definition, the main thread.
For an iOS app the system sets things up so that this main thread calls the main executable’s main function.
The main function must call in to one of the standard UI frameworks which is then responsible for running the run loop. For example, for UIKit the main function is expected to call UIApplicationMain.
Note If you’re using Swift, you can use the @main attribute to decorate a main type which then takes over the task of providing the main function and calling in to the relevant UI framework.
All of the above applies to apps running on iOS and its child platforms. There are a number of important nuances on macOS. However, it’s still true that every process starts with one thread that acts as the main thread.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"