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.m
function. As in any C program, the execution of Objective-C applications start frommain
(). You need to create themain
() function in themain.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 theUIApplicationMain
() 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 anil
is specified, theUIApplication
class is used ...
Get iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.