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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -