IOS program starts
The underlying environment setup before the main function (Code copying, memory opening, and other operations related to starting a process) is not described. We start with the main function.
1 main Function
Int main (int argc, char * argv []) {NSLog (@ "===% s", argv [0]); @ autoreleasepool {// function prototype: // int UIApplicationMain (int argc, char * argv [], NSString * principalClassName, NSString * delegateClassName); return UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate class]);}
The code is not changed. The first is an automatic release pool to ensure that the memory is released at the end. The following describes the parameters:
Argc and argv: the parameter of the Standard C. argc is the number of elements in the argv array. Argv generally has an element argv [0], that is, the path of the current executable program. (In addition, in linux, we can open a program through a terminal to pass parameters to it. If the parameter is automatically ignored in the square brackets );
PrincipalClassName: Specifies the application class, which must be a UIApplication (or subclass ). If it is nil, The UIApplication class is used as the default value. It is a Singleton, representing a process and the first object created by the program, can perform some application-level operations;
DelegateClassName: Specifies the proxy class of the application class, which must comply with the UIApplicationDelegate protocol.
2 UIApplicationMain
1) create a UIApplication object based on the input parameters;
2) create a delegate object for UIApplication Based on the passed parameters, and assign the delegate object to the delegate attribute in the UIApplication object.
3) Enable a message loop
The following sections describe how to start a storyboard or not start a storyboard.
# Storyboard ##
3 AccordingInfo. plistLoad storyboard
1) create a UIWindow. A UIWindow is a special type of UIView. Generally, there is only one UIWindow in an App (note that there are other ones, such as the pop-up keyboard ). Set as the main window. There is only one main window at the same time. You can use [UIApplication sharedApplication]. keyWindow to obtain the window.
2) create and set the rootViewController of the UIWindow.
3) display window
# No storyboard ##
3. The delegate object starts to process (Listen) system events (no storyboard)
1) when the program is started, the agent's application: didfinishlaunchingwitexceptions: method will be called.
2) create a UIWindow: window in application: didFinishLaunchingWithOptions:
3) Create and set the rootViewController of the UIWindow.
4) display and set window as the main window: [window makeKeyAndVisible]; then self. window = window; to prevent being released.