IOS Dev (38) You may not understand the main. m file

Source: Internet
Author: User

IOS Dev (38) You may not understand the main. m file

  •  
  • First look at the code
    #import 
        
         #import AppDelegate.hint main(int argc, char * argv[]){    @autoreleasepool {        return UIApplicationMain(argc, argv, nil,        NSStringFromClass([AppDelegate class]));    }}
        

    What has it done?

    There are two key points: one is to automatically release the pool autorelease pool. This item is added after iOS5 introduces Auto Reference Counting. Note that this item means a corresponding thread (here, it is the main thread ). For a multi-threaded Application, you should prepare the autorelease pool for other threads.

    Another key point is UIApplicationMain. The most basic function is to create an Application object. Second, it will also create the corresponding Delegate object (Delegate), and the Application will call the corresponding protocol method when the Application has a corresponding state change. This product is responsible for building the Event Loop of applications, which can continuously receive interactive operations, such as screen Touch gestures, various sensors (gravity accelerators, gyroscope, etc.

    Why can't I see the UIApplication instance?

    We know that an application that can be used out must have at least one UIApplication as the subject to receive various types of events. There is also a UIApplicationDelegate to handle the events. Simply put, the former receives events and the latter processes events.

    The code for receiving the event is written by iOS. You only need to write the code for processing the event. UIApplicationMain automatically creates a UIApplication ". You don't have to worry about what's going on in it.

    All you need to do is set UIApplicationDelegate. After the project is created, there is an AppDelegate product there. The code for this item is as follows:

    #import 
        
         @interface AppDelegate : UIResponder 
         
          @property (strong, nonatomic) UIWindow *window;@end
         
        

    Is that clear. Then you can look at the AppDelegate. m file to know how this product handles events (in fact, there is no code, and the code is encapsulated in UIApplicationDelegate ).

    Reprinted please indicate the blog from laruence: http://blog.csdn.net/prevention

     

Related Article

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.