You are on page 1of 6

Basic Project Structure for iPhone FrameWork

After having some fare knowledge about the Objective C language, we now start with the iPhone development. The best way to learn any thing is to take up a test case. We will start our learning from a test case. We will make an application, which will have four sections. Each section will display various components and concept of iPhone. In order to start developing iPhone app we require Xcode. So first click XCode icon. We start by selecting New Project from the File Menu of the Xcode. A screen shows up which displays options of various templates as shown below

Nimap Infotech , B-204, Pawapuri Apts, Love Lane, Mumbai 400010. Tel.:- +91 986 935 7889 Email:- info@nimapinfotech.com Web:- www.nimapinfotech.com

As you can see above there are lot of templates provided by the Xcode to start the respective project. Template helps us to start our app in proper way with lot of basic things directly done on our behalf. We will select View Based application, as UIView is basic component in iPhone development, which is used to display various user interfaces to the user. When you select choose button, you will be presented by the pop up window, where you give name to your project. For the application, which we are developing, we will give it name say FirstProject and click save.

Nimap Infotech , B-204, Pawapuri Apts, Love Lane, Mumbai 400010. Tel.:- +91 986 935 7889 Email:- info@nimapinfotech.com Web:- www.nimapinfotech.com

Once you select save, Xcode opens up your project as shown below

We will see first left side section of Groups & Files, which explore out entire project created by the Xcode. We will expand Classes folder to see what all files get created.

Nimap Infotech , B-204, Pawapuri Apts, Love Lane, Mumbai 400010. Tel.:- +91 986 935 7889 Email:- info@nimapinfotech.com Web:- www.nimapinfotech.com

As you can see two classes are formed (four files each class in objective c has two files one for interface .h and other implementation .m), FirstProjectAppDelegate and FirstProjectViewController. The AppDelegate file captures the entire life cycle of the application. Its remains in the memory till the time application is active. All the OS related notifications are capture by this class. The application developed for iPhone follow MVC architecture. MVC stands for Model-View-Controller. This architecture is highly recommended for any big system. Under this architecture a system gets divided into three major sections namely Model, which keeps all the data of the application, which will be manipulated. View; which will displays various UI to the user to interact with the application as well as result of the interaction. And Controller, which controls the entire system such handling of various user interactions, implementation of business logic and so on. We will go in details of these classes later on, now lets expand the other sources folder.

Nimap Infotech , B-204, Pawapuri Apts, Love Lane, Mumbai 400010. Tel.:- +91 986 935 7889 Email:- info@nimapinfotech.com Web:- www.nimapinfotech.com

This folder consists two files; one is Prefix files, which is access by all the classes in the application. This is a header file basically one can defines macros out here. Other file is main class, which is the starting point of the application. The main class contains following lines of code

#import <UIKit/UIKit.h> int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } We never change these lines of code. The first line states that we will import the UIKit class, which contains definition of all the user interface components of the iPhone. Every application has one pool associated with it. Pool basically keeps all the component of the application. When application dies system empty this pool. Application starts execution with UIApplicationMain(argc, argv, nil, nil); function call. This function tells OS to start the application notification to the delegate class and thus control is Nimap Infotech , B-204, Pawapuri Apts, Love Lane, Mumbai 400010. Tel.:- +91 986 935 7889 Email:- info@nimapinfotech.com Web:- www.nimapinfotech.com

passed to the delegate class, which is present in the Classes folder. As we told you earlier that control is passed from main class to the delegate class. Lets first see interface file of the delegate file, which declares the structure of the delegate class. Following is the code written in this file

#import <UIKit/UIKit.h> @class FirstProjectViewController; @interface FirstProjectAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; FirstProjectViewController *viewController; }
@property (nonatomic, retain) UIWindow *window; @property (nonatomic, retain) FirstProjectViewController *viewController;

@end

As we told you before, each class in the objective should be child of NSObject class. Thus FirstProjectAppDelegate inherits from the NSObject which one can find from the following line
@interface FirstProjectAppDelegate : NSObject

Thus after the class name we have to put colon : and than name of the class from which we want to derive. In this FirstProjectAppDelegate derives from NSObject.

Nimap Infotech , B-204, Pawapuri Apts, Love Lane, Mumbai 400010. Tel.:- +91 986 935 7889 Email:- info@nimapinfotech.com Web:- www.nimapinfotech.com

You might also like