Skip to Main Content
iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch
book

iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch

by Maher Ali
March 2009
Beginner to intermediate content levelBeginner to intermediate
396 pages
8h 44m
English
Wiley
Content preview from iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch

Chapter 3. Anatomy of an iPhone Application

In this chapter, we discuss the basic steps needed to build a simple iPhone application. First, we demonstrate the basic structure of a simple iPhone application, and then we show the steps needed to develop the application using XCode.

HelloWorld Application

In this section, we demonstrate the basic structure of a simple iPhone application. The application simply displays the message Hello World to the user. The following are the steps needed to write such an application.

  1. Create a main.m function. As in any C program, the execution of Objective-C applications start from main(). You need to create the main() function in the main.m file as follows:

    #import <UIKit/UIKit.h>
    
    int main(int argc, char *argv[]) {
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
      int retVal = UIApplicationMain(argc, argv, nil,
                          @"HelloWorldAppDelegate");
      [pool release];
      return retVal;
    }

    The main() function starts by creating an autorelease pool and ends by releasing it. In between, it makes a call to the UIApplicationMain() function. UIApplicationMain() is declared as follows:

    int
     UIApplicationMain(int argc, char *argv[],
        NSString *principalClassName,
        NSString *delegateClassName
    )

    This function takes four parameters. The first two parameters are the parameters passed in to the main() function. These parameters should be familiar to any C programmer. The third parameter is the name of the application class. If a nil is specified, the UIApplication class is used ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft® Office Access 2007 on Demand

Microsoft® Office Access 2007 on Demand

Steve Johnson - Perspection, Inc.
FileMaker Pro 14: The Missing Manual

FileMaker Pro 14: The Missing Manual

Stuart Gripman, Susan Prosser
Microsoft® Office Access™ 2007 Step by Step

Microsoft® Office Access™ 2007 Step by Step

Steve Lambert Joan Lambert and M. Dow Lambert III

Publisher Resources

ISBN: 9780470742822Purchase book