ios - Objective C substite method trigger name with string -
i've got array contains name of function , parameter looks this.
( [0] => ( [0] => @"getname" [1] => @"this name" ) )
and method, looks this.
-(nsstring *)getname:(nsstring *)name {...}
i know trigger method have [[appdelegate alloc] getname:string];
there way substitute getname
array[0][0]
, string
array[0][1]
?
here's working example of @chiquis idea. (note selector needs trailing colon):
-(void)dosomethingalittledangerous nsarray *array = @[@[@"getname", @"this name"]]; nsstring *notquitetheselectorstr = array[0][0]; nsstring *selectorstr = [notquitetheselectorstr stringbyappendingstring:@":"]; sel selector = nsselectorfromstring(selectorstr); // generates warning because compiler cannot confirm // self implements programmatically derived selector if ([self respondstoselector:selector]) { nsstring *name = [self performselector:selector withobject:array]; } nslog(@"%@", name); } - (nsstring *)getname:(nsarray *)array { return array[0][1]; }
Comments
Post a Comment