When developing an iPhone program, the first thing that comes into use is not the source code, but the project files and directories. Let's take a look at its composition.
IPhone application directory structure
IPhone applications are placed in a secure structure called sandbox. The program can only access resources in its own sandbox.
IPhone applications and Mac OS applications are basically the same, but there are some differences in the program directory. You can use AddressBook to construct other functions or constructor.
The directory structure of the iPhone application is as follows:
/Applications/
[Application1]/
Application1.app
Documents/
Library/
Tmp/
[Application2]/
Application2.app
Documents/
Library/
Tmp/
Composition of Project
Although the composition of a project varies by program, it is basically based on the MVC Model. Therefore, the directory form is organized according to Model, Controller, and View.
For example, the following directory structure:
Classes
Libraries (various middleware, Libraries, etc)
JSON
ImageStore
Other program modules
Controllers (Class Related to View Controller)
UIApplicationDelegate
UIViewController
Views (custom view and Program Interface)
Subclass of UITableViewCell
Subclass of UIView
Project file structure
Next, let's take a look at what is in the program project:
HelloWorld
| -- Classes
| -- HelloWorldAppDelegate. h
| -- HelloWorldAppDelegate. m
| -- HelloWorldViewController. h
| '-- HelloWorldViewController. m
| -- HelloWorld. xcodeproj
| -- HelloWorldViewController. xib
| -- HelloWorld_Prefix.pch
| -- Info. plist
| -- MainWindow. xib
| -- Build
| '-- HelloWorld. build
'-- Main. m
. Pch
Pre-compiled header files are often encountered in win32, which also contains common header files.
. Plist
Includes the features of the project, such as the project name, default loaded nib file, and version.
. Xib
Program resource file. It is used to simplify the coding process and improve development efficiency.
Main. m
The iphone program entry is similar to the main function in C/C ++.
The main function is as follows:
Int main (int argc, char * argv []) {
NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init];
Int retVal = UIApplicationMain (argc, argv, nil, nil );
[Pool release];
Return retVal;
}
The parameters argc and argv [] of the main function are the same as those in the C language and support command line input.
Next, create an NSAID utoreleasepool object to automatically manage the program memory.
1 NSAID utoreleasepool * pool = NSAID utoreleasepool alloc] init];
The most important thing is the call of the following UIApplicationMain, which completes the system startup process and forms an event-driven.
1 int retVal = UIApplicationMain (argc, argv, nil, nil );
Next we will explain how to start the iPhone application.
Author: Yi Feiyang