The main function and uiapplication of IOS restudying

Source: Internet
Author: User

Like the C + + program has an entry function like the main function, IOS app development also has the same portal main function.

However today found in the revision of the old version of the program found that with the new version of Xcode created by the main function is a little different

This is the main function code that is now created with Xcode6.3:

int main (int argc, char * argv[]) {

@autoreleasepool {

Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]));

}

}

This is what the main function code looks like after the 4.2 version of Xcode was converted to Arc:

1 int Main (intChar *argv[])2{3     @autoreleasepool {4         int retVal = uiapplicationmain (argc, argv, nil, nil); 5         return retVal; 6     } 7 }

It is found that the parameters passed by the Uiapplicationmain function are also different, why not the last parameter changed?

The Uiapplicationmain () function is the entrance to the program.

Uikit_extern int uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString *delegateclassname);

IF Nil is specified for Principalclassname, the value of Nsprincipalclass from the info.plist is used. If there is no

Nsprincipalclass key specified, the UIApplication class is used. The delegate class would be instantiated using init.

Principalclassname: look at the word meaning is not difficult to understand, the main class name. If this parameter is the value of Nsprincipalclass this key in Nil,info.plist (actually shown as Principal class in Info.plist), If Nsprincipalclass has no value, the default uiapplication. Principalclassname must be the name of UIApplication or its subclass, which represents the current iphone program itself, This program will read the Info.plist file for configuration information, including the value of the main nib file, typically MainWindow (. xib);

Delegateclassname: The proxy class. Try to set this parameter to nil in the new version, you will find the emulator is black after startup, try to break the point in the Didifinishlaunchwithoption function in Appdelegate it's not stopping at all. Why is nil the previous version of this parameter?

The Mainwindow.xib file follows the class name of the Uiapplicationdelegate class, because uiapplication defines a delegte variable that should follow the uiapplicationdelegate, which is responsible for controlling the program's operation if the main NI b file does not have this class, you should customize a class like this, and change the fourth parameter to the class name of the class, otherwise the program does not know how to operate, because the first three parameters represent the application itself, in addition to the application of the event loop to start up, and read the configuration information in the Info.plist, do nothing else. If the parameter is nil, the program assumes that the program's proxy is from the main nib file.

The main function and uiapplication of IOS restudying

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.