The XCode version I used is 5.
Create an ios project and select Empty Application
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + kernel/J + kernel/zMGqz + kernel + qICBtYWluLm3OxLz + PC9wPgo8cD48L3A + CjxwcmUgY2xhc3M9 "brush: java;"> # import # Import "AppDelegate. h" // The Name Of AppDelegate can be changed. I use the default one. Int main (int argc, char * argv []) {@ autoreleasepool {return UIApplicationMain (argc, argv, nil, NSStringFromClass ([AppDelegate class]);}We can see the main function that we are no longer familiar. Object-C inherits the main function feature of C. When we start the ios application, the main function is executed after the preparation is completed during the runtime.
In the above Code, except the @ autoreleasepool command, the main function has only one line of code.
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
This line of code also returns directly, so we can infer that the UIApplicationMain function executes an "endless loop", so that the application can run on this line of code and will not end immediately. This "endless loop" is similar to windows message loop.
Note that the 4th parameter of the UIApplicationMain function, NSStringFromClass ([AppDelegate class]), is a string value, that is, you can replace it with the @ "AppDelegate" constant string.
return UIApplicationMain(argc, argv, nil, @"AppDelegate" );
UIApplicationMain creates an AppDelegate instance using reflection.
For more information, see "UIApplicationMain Introduction ".
Authorization class AppDelegate
Open the Declaration file of the AppDelegate class
#import
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;@end
AppDelegate inherits from UIResponder and complies with the UIApplicationDelegate protocol. UIApplicationMain communicates with AppDelegate through the UIApplicationDelegate protocol.
AppDelegate has a window of the UIWindow * type.
Open the implementation file of the AppDelegate class, which contains the default implementation of the UIApplicationDelegate protocol.
The didfinishlaunchingwitexceptions implementation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES;}
We can see that the window Member of the AppDelegate instance is initialized here. Generally, the window is the first window view of the ios application.
In the code, the background color of the window is white [UIColor whiteColor], and makeKeyAndVisible makes the window visible and displayed on the screen.
Execution Process Diagram