iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch
by Maher Ali
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.
Create a
main.mfunction. As in any C program, the execution of Objective-C applications start frommain(). You need to create themain() function in themain.mfile as follows:#
import<UIKit/UIKit.h>intmain(intargc,char*argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];intretVal = UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate"); [pool release];returnretVal; }The
main() function starts by creating an autorelease pool and ends by releasing it. In between, it makes a call to theUIApplicationMain() function.UIApplicationMain() is declared as follows:intUIApplicationMain(intargc,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 anilis specified, theUIApplicationclass is used ...