P. 1
iPhone App Programming Guide

iPhone App Programming Guide

|Views: 282|Likes:
Published by Lukasz81

More info:

Published by: Lukasz81 on Aug 22, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/22/2011

pdf

text

original

#import

int main(int argc, char *argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;

}

Note: An autorelease pool is used in memory management. It is a Cocoa mechanism used to defer the
release of objects created during a functional block of code. For more information about autorelease pools,
see Memory Management Programming Guide. For specific memory-management guidelines related to
autorelease pools in iOS applications, see “Allocate Memory Wisely” (page 107).

TheUIApplicationMain function at the heart of your application’smain function takes four parameters
and uses them to initialize the application. Although you should never have to change the default values
passed into this function, it is worth explaining their purpose in terms of starting the application.

■ Theargc andargv parameters contain any launch-time arguments passed to the application from the

system. These arguments are parsed by the UIKit infrastructure and can otherwise be ignored.

■ The third parameter identifies the name of the application’s principal class. This is the class responsible

for running the application. Specifyingnil causes UIKit to use theUIApplication class, which is
recommended.

■ The fourth parameter identifies the class of the application delegate. The application delegate is

responsible for managing the high-level interactions between the system and your custom code.
Specifyingnil tells UIKit that the application delegate object is located in the application’s main nib
file (which is the case for applications built using the Xcode templates).

In addition to creating the application object and creating or loading the application delegate, the
UIApplicationMain function also loads the application’s main nib file. All Xcode projects have a main nib
file by default, and this file typically contains the application’s window and the application delegate object.
UIKit obtains the name of the main nib file from theNSMainNibFile key in the application’sInfo.plist
file. Although you should rarely need to do so, you can designate a new main nib file for your application by
changing the value of this key before building your project. For more information about theInfo.plist
file and how you use it to configure your application, see “The Information Property List” (page 87).

28

The Application Life Cycle

2010-11-15 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER2

The Core Application Design

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->