Relationship between uiapplicationmain, uiapplication, and uiapplicationdelegate protocols

Source: Internet
Author: User

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,UIApplicationAssigned 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.