Home > 2010 Fall DPS913 > iOS app structure and startup

iOS app structure and startup

September 16, 2010 Leave a comment Go to comments

Let’s examine the structure of a typical iOS app, and how it starts up.

.

Now that you have been introduced to Objective-C, Cocoa, and the development tools, let’s examine the structure of a typical iOS app. We briefly covered this topic at times during our introductory sessions, so let’s summarize the coverage now.

.

iOS app structure

All apps have a main.m, which contains the app’s entry point, a function called main().

The main() function initializes an “application” object (you can think of this as the runtime environment for the app).

Then, in a typical configuration, the app’s main nib file is loaded. (The name of the nib file is seen in <appname>-Info.plist.)

The nib file loads, and by configuration, causes the application delegate to load. The application delegate implements methods that handle application-level events. Then, typically, the app’s initial view and view controller are initialized, and control is passed to the view controller.

After that, user interaction and other events in the environment will determine what happens next.

A typical app, therefore, has the following components (that make up its structure):

  • main() function, in main.m
  • configuration info located in <appname>-Info.plist
  • application delegate (<appname>AppDelegate.h and .m)
  • initial view (nib file) and view controller (.h and .m)
  • other views and view controllers
  • resources like images and so on
  • app icon, as a 57px square PNG-format image

.

iOS app startup

What is the typical startup sequence? What happens, and in what order? The following details the steps:

  1. The app is launched by the user
  2. The main() function is the entry point, and runs
  3. The UIApplicationMain() function is called
  4. The application (singleton) object is created (i.e. the runtime environment for the app)
  5. <appname>-Info.plist is examined, and the nib file named in “Main nib file base name” is loaded (which means that all of its objects are initialized, and connections are established)
  6. As part of the nib loading, the awakeFromNib: method is called on all the objects that it initialized
  7. The runtime sends the applicationWillFinishLaunching: message to the application delegate
  8. The nib’s File’s Owner object has an instance variable named “delegate”; the object that it points to is the application delegate, which is then initialized
  9. The runtime sends the application:didFinishLaunchingWithOptions: message to the application delegate

A subsequent view is initialized by loading a nib. Its view controller is then initialized, because the view controller is configured as the nib’s File’s Owner.

You can see the results in the “Events 1” example app. When you run it, the app will use NSLog() function calls to write information to the debugger console as specific methods are called by the Cocoa runtime.

.


Advertisements
Categories: 2010 Fall DPS913
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: