OC will not be the runtime is not understand OC. Recent projects need to do some hot updates, go with a review.
The first thing to know is the OC message mechanism. Nonsense not much to say, directly on the code and comments.
////main.m//Rumtime////Created by 123 on 16/7/4.//copyright©2016 year yipinbaike. All rights reserved.//#import<Foundation/Foundation.h>#import<objc/message.h>@interfacePerson:nsobject- (void) run;+ (void) run;- (void) EatWith: (nsstring*) food;@end@implementation Person- (void) run{NSLog (@"Object Method Run");}+ (void) run{NSLog (@"class method Run");}- (void) EatWith: (nsstring*) food{NSLog (@"ate:%@", food);}@endvoidText1 ();voidText2 ();intMainintargcConst Char*argv[]) {@autoreleasepool {//Text1 ();Text2 (); } return 0;}#pragmaMark--Message mechanism/*OC methods and C language functions are not the same, OC at compile time is not known which function is actually called, only the real run time through the function name to find the actual function to invoke the OC language is a message mechanism, for example, in Text1, the sequence of calls from top to bottom three methods. *///1. Test message mechanism (without parameters)voidText1 () {//Instance Object MethodsPerson * person =[[Person alloc]init]; [Person run]; [Person Performselector: @selector (run)]; Objc_msgsend (person, @selector (run)); //Class Object Methods//It is important to note that direct use of objc_msgsend (person, @selector (run)) is not allowed. Because the nature of the invocation of a class method is to convert the class name into a class object. The person is just a class name and cannot call the message function directly objc_msgsend ()Class Personclass = [personclass]; [Personclass Run]; [Personclass performselector: @selector (run)]; Objc_msgsend (Personclass, @selector (Run));}//2. Test message mechanism (with parameters)voidText2 () {//Note that Performselector has a limited number of arguments for this function, which is usually done with a dictionary or an array .Person * person =[[Person alloc]init]; [Person EatWith:@"steamed Bun"]; [Person Performselector: @selector (eatwith:) Withobject:@"steamed Bun"]; Objc_msgsend (person, @selector (eatwith:),@"steamed Bun");}
It is important to note that
1. Run the above code to import #import <objc/message.h>
2. You need to set the property to No (check the message mechanism) in the search msg, Build Setting
Runtime (i): message mechanism