[IOS] @UIApplicationMain

Source: Internet
Author: User

When you create a swift project, you find that the project structure is concise, there is no. pch file, and there is a. main file,

Naturally will not find the main function of the entrance, an instant on the app's startup process is not a clue, open appdelegate.swift

At the beginning, I found @UIApplicationMain familiar name, and the first thought was in the OBJC project.

int main (int argc, char * argv[]) {    @autoreleasepool {        return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Senappdelegate class]);}    }

As a matter of course, it is believed that a symbol and a word in swift are equal to a main.m file, so efficient!!!

I really do not want a bit of redundant code AH This is, worship Ah, Swift's efficiency is evident.

First look at the official details of the little Apple


Then we looked at Swift's declaration, and the OBJC changed quite a lot, compared with the two attribute declarations in uiapplication.

1.0@property (nonatomic,readonly) UIWindow *keywindow; @property (nonatomic,readonly) Nsarray  
Vs

1.0    var Keywindow:uiwindow? {Get}    


The contrast is self-evident ~ ~

Same as the official said, you can add your own main.swift specifies the delegate name of the response, the code is as follows:

Import Foundationimport Uikituiapplicationmain (C_ARGC, C_ARGV, Nsstringfromclass (uiapplication), NSStringFromClass ( Appdelegate))

Careful research, swift writing projects in addition to grammatical, and other aspects of the changes are quite large ...

Finally, just to say that the programmer is happy, the code efficiency is high ...

Learn from the beginning ...


[IOS] @UIApplicationMain

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.