ios - Execute ObjC function from NSstring -
this question has answer here:
this stupid question execute function in objc, example this:
nsstring *function = @"-(void)execute{nslog(@"123");}"
how execute string become function?
i think looking for,
1. no parameter
sel aselector = nsselectorfromstring(@"execute"); [self performselector:aselector];
simulation:
-(void)execute;
2. single parameter
sel singleparamselector = nsselectorfromstring(@"methodwithoneparam:"); [self performselector:singleparamselector withobject:first];
simulation:
-(void)methodwithoneparam:(nsstring*)first;
3. multi parameter
sel doubleparamselector = nsselectorfromstring(@"methodwithfirst:andsecond:"); [self performselector: doubleparamselector withobject: first withobject: second];
simulation:
-(void)methodwithfirst:(nsstring*)first andsecond:(nsstring*)second;
Comments
Post a Comment