The iPad and iPhone App Life Cycle - dummies

By Neal Goldstein, Dave Wilson

Although simple for the eventual user, the birth, life, and death of an iOS application is a pretty complex process. In this article, see what happens throughout the time that the user launches the app from the Home screen, uses the app, and then stops using the app, either because she is done or decides to respond to an interruption such as an SMS message.

The life of an iOS app begins when a user launches it by tapping its icon on the Home screen. The system launches your app by calling its main function — which Xcode kindly lets you peek at if you go to the Project navigator, open the disclosure triangle next to the Supporting Files group, and select main.m.

The details of the implementation shown here may change, but the overall architecture will stay the same from one iOS version to another.

#import <UIKit/UIKit.h>
#import "RTAppDelegate.h"
int main(int argc, char *argv[])
  @autoreleasepool {
      return UIApplicationMain(argc, argv, nil, NSStringFromClass([RTAppDelegate class]));

The main function is where a program starts execution. This function is responsible for the high-level organization of the program’s functionality and typically has access to the arguments given to the program when it gets executed.

The main function does only these two things:

  1. Sets up an autorelease pool:

    @autoreleasepool {

    This is a piece of memory-management plumbing that you don’t need to often (other than here), or perhaps ever, but feel free to investigate on your own if you are interested.

  2. Calls the UIApplicationMain function to create the application object and delegate and set up the event loop:

    return UIApplicationMain(argc, argv, nil, 
                NSStringFromClass([RTAppDelegate class]));

    This is your entrance into the entire application startup process and its underlying architecture.