IOS Application core architecture

A new IOS application program is mainly composed of the following files:
main.m
*appDelegate.h/.m
MainWindow.xib
*info.plist
IOS applications are encapsulated by UIKit, and the standard implementation of the main function of an Application application is as follows:

int main(int argc, char *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}
Among them, NSAutoreleasePool does automatic memory release, and autorelease suspends the release operation.

The core is the UIApplicationMain() function, UIKit encapsulates the initialization work, loads the user interface of the application and starts the event loop. Its third and fourth parameters receive NSString* type parameters, which are used to specify the class name.
The third parameter specifies: UIApplication class. If the value of the primary class string is nil , UIKit uses the UIApplication class by default; if it is not empty, the application uses the specified custom subclass of the UIApplication class (This practice is not recommended, but it is indeed possible).
The fourth parameter specifies: AppDelegate. If the app delegate class is nil, UIKit will assume an object in the app's main nib file (for apps created through the Xcode template) as the app's delegate object.
UIApplication and AppDelegate
UIApplication is the core of the app application. It is responsible for the processing logic of events. It distributes application-related events such as touch screen processing to the corresponding FirstResponder, and notifies related operations down through AppDelegate. UIApplication is the processing core applicable to any application. It allows different programs to generate different actions and behaviors through AppDelegate.
main nib file
The default is MainWindow.xib, specified by NSMainNibFile in *info.plist. If the application's information property list ( Info.plist ) file contains a NSMainNibFile key, the UIApplication object loads the nib file specified by that key as part of the initialization process. The main nib file is the only nib file that is automatically loaded, other nib files can be loaded later as needed.
The main nib file of an iPhone application usually contains a window object and an application delegate object, and may also contain one or more other important objects that manage windows. Loading a nib file causes the objects in the file to be reconstructed, converting the on-disk representation of each object into an in-memory object that the application can manipulate. There is no difference between objects loaded from a nib file and objects created programmatically. However, for user interfaces, it is often more convenient to create objects associated with the user interface graphically (using the Interface Builder program) and store them in nib files rather than programmatically.
The basic process of program startup of standard ViewBase project
Call UIApplicationMain() in the program entry main, the 3 and 4-bit parameters are default parameters, use the default UIApplication class, use the AppDelegate class specified in the NIB and set it to UIApplication. Load the NIB file, construct AppDelegate, create Window window, and create UIViewController. The application framework is started and completed, UIApplication processes and distributes the event logic, and the application executes normally in the event loop.

좋은 웹페이지 즐겨찾기