Detailed analysis of iOS project file main.m

Source: Internet
Author: User
Tags uikit

iOS project file main.m is actually an OC a class of. m files, why we can not see this file immediately when the file is an OC class. m file?

Since 1. OC Class General first Letter capital

2.OC classes typically have. h files

First, the main.m file in Xcode7.3 's new project.

#import <uikit/uikit.h>//loaded into the Uikit frame UIKit.h file, in fact, only for a UIApplication.h uiapplicationmain C language function
#import "AppDelegate.h"//loading AppDelegate.h file, in fact, only for one OC method Nsstringfromclass required Parameters--, personal feeling all sorts of fuss over

The code is as follows Copy Code
int main (int argc, char * argv[]) {
@autoreleasepool {
According to the information printed on the console:
NSLog (@ "argc =%d", argc);//int argc is 1.

NSLog (@ "argv[] count =%lu", sizeof (argv)/sizeof (argv[0));//c char array count is 1
NSLog (@ "argv[0] =%s", argv[0]);//print string knowable argv[0] is a path

NSLog (@ "Bundlepath =%@", [NSBundle Mainbundle].bundlepath);//And [NSBundle Mainbundle].bundlepath print results comparison, argv[0] = = [ NSBundle Mainbundle].bundlepath is True
To learn more about ARGC,ARGV can refer to the following URLs
Http://wenku.baidu.com/link?url=xNNFYFd3kGS0fj79e_hKbQnnO6t_ Tiubln8dmunq-k7oqyj9uftzy5hppkcwkku3ck1eyacmg8ybrpmh5vtdushsl_em2nrqi0bjlgcl5dy
Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]);//uiapplicationmain returns a number of type int, Nsstringfromclass ([Appdelegate class]) in fact, the return value of this method is a NSString object @ "Appdelegate", can be directly written as @ "Appdelegate"
}
}

Console information:

The code is as follows Copy Code

ARGC = 1
argv[] Count = 1
Argv[0] =/library/developer/coresimulator/devices/ea9e0ae1-9ee8-4246-aa72-f39ed66fd2f7/data/containers/bundle/ Application/ae119964-3712-4c12-8fa7-acb8d663e59b/testapp.app/testapp
Bundlepath =/library/developer/coresimulator/devices/ea9e0ae1-9ee8-4246-aa72-f39ed66fd2f7/data/containers/ Bundle/application/ae119964-3712-4c12-8fa7-acb8d663e59b/testapp.app
Omit some personal information

Super Lite version main.m (test can run the program correctly)

  code is as follows copy code


#import <uikit/uiapplication.h>
 
int main (int argc, char * argv[]) {
    @autoreleasepool {
        return Uiapplicationmain (argc, argv, nil, @ "appdelegate");
   }
}

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.