Main. m is the entry to iPhone program execution.
A typical main. M file is as follows:
#import <UIKit/UIKit.h>#import "AppDelegate.h"int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}
Appdelegate. H is a header file. The app in the header file name is specified by the class prefix when the project is created. The delegate is automatically added because it inherits the uiapplicationdelegate protocol.
In the main. M file, the method declaration of uiapplicationmain is as follows:
Int uiapplicationmain (
Int argc,
Char * argv [],
Nsstring * principalclassname,
Nsstring * delegateclassname
);
When the third parameter is nil,UIApplication
Assigned to uiapplicationmain;
The fourth parameter inherits the class of uiapplicationdelegate: appdelegate
The definition of appdelegate is as follows:
#import <UIKit/UIKit.h>@interface AppDelegate : NSObject <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end
The implementation of appdelegate is as follows:
#import "AppDelegate.h"@implementation AppDelegate@synthesize window = _window;@end
Therefore,
Uiapplicationmain is the only method in the main method and is the entry to the iPhone execution program.
The third parameter of uiapplicationmain isUiapplication (or its subclass)
The fourth parameter is the class that implements the uiapplicationdelegate protocol.