Using runtime call method, can be implemented without import, directly call
Build setting--> Apple LLVM 6.0-preprocessing--> Enable Strict Checking of Objc_msgsend Calls change to NO
-(void) ExecFunction2
{
NSString *functionname = @ "Runwithfriend:";
NSString *classname = @ "People";
NSString *friend = @ "Sister";
SEL runaction = nsselectorfromstring (functionname);
Class Peopleclass = nsclassfromstring (className);
Objc_msgsend (Peopleclass, runaction, friend);
}
Static Nsmutabledictionary *cache;
-(void) execfunction
{
if (!cache)
cache = [Nsmutabledictionary dictionary];
NSString *functionname = @ "Runwithfriend:";
NSString *classname = @ "People";
NSString *friend = @ "Sister";
SEL runaction = nsselectorfromstring (functionname);
Class Peopleclass = nsclassfromstring (className);
Nsmethodsignature *runsig;
if ([Cache Objectforkey:functionname]) {
Runsig = [Cache objectforkey:functionname];
} else {
///Methodsignatureforselector: More cost-performance, so it's best to cache the signature.
Runsig = [Peopleclass methodsignatureforselector:runaction];
[Cache Setobject:runsig Forkey:functionname];
}
Nsinvocation *INV = [Nsinvocation Invocationwithmethodsignature:runsig];
[Inv Setselector:runaction];
[Inv Setargument:&friend Atindex:2];
[Inv Invokewithtarget:peopleclass];
}
IOS uses runtime to invoke methods