[IOS] UIApplicationMain

Source: Internet
Author: User

[IOS] UIApplicationMain

After a new swift project is created, it is found that the project structure is very simple and there is no. pch file or. main file,

Naturally, you won't find the main function entry, and you have no clue about the app startup process. Click AppDelegate. swift.

@ UIApplicationMain is a familiar name. The first thing that comes to mind is in the Objc Project

 

int main(int argc, char * argv[]){    @autoreleasepool {        return UIApplicationMain(argc, argv, nil, NSStringFromClass([SENAppDelegate class]));    }}

 

Naturally, it is considered that a symbol and a word are equivalent to a main. m file in swift, which is efficient !!!

Nima, I really don't want to have any redundant code. This is, worship, swift's efficiency can be seen from this.

First, let's take a look at Apple's official explanation.

Then I read the swift declaration method, which is quite different from Objc. I compared the two attribute declarations in UIApplication.

 

1.0@property(nonatomic,readonly) UIWindow *keyWindow;@property(nonatomic,readonly) NSArray  *windows;2.0 - (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0); 
VS

 

 

1.0    var keyWindow: UIWindow? { get }    var windows: [AnyObject] { get }2.0
    @availability(iOS, introduced=3.0)     func canOpenURL(url: NSURL) -> Bool 

 

 

Self-evident comparison ~~

 

Similarly, as officially said, you can add the delegate name of the response specified by main. swift by yourself. The Code is as follows:

 

import Foundationimport UIKitUIApplicationMain(C_ARGC, C_ARGV, NSStringFromClass(UIApplication), NSStringFromClass(AppDelegate))

After careful research, in addition to syntax, the swift write project also changes a lot in other aspects...

 

Finally, I just want to say that programmers are happy, and the code efficiency is high...

 

 

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.