There is a requirement, I need to call method from other class, but the method name is changed with different actions, something like below:
NSArray *arrays = [NSArray arrayWithObjects:@"aaa", @"bbb", nil];
for ( NSString *array in arrays ){
blablabla.......
Aclass *abc = [[Aclass alloc] methodName%@:variable],array;
blablabla.......
}
Is there any way to write code like that in Objective-C?
Thanks!
more info: the method name in Aclass is like:
-(NSArray *)procWithAAA:(NSInteger)aaaID
Thanks!
the method name in Aclass is like:
-(NSArray *)procWithAAA:(NSInteger)aaaID
---------as you guys's suggestion, i write code like below, but it doesn't work-------
NSArray *arrays = [NSArray arrayWithObjects:@"aaa", @"bbb", nil];
for ( NSString *array in arrays ){
SEL customSelector = NSSelectorFromString([NSString stringWithFormat:@"procWith%@", array]);
if ([Sync respondsToSelector:customSelector]) {
Aclass * abc = [Aclass performSelector:customSelector:aaaID];
}else {
NSLog(@"## Class does not respond to %@", customSelector);
}
Aclass * abc = [Aclass performSelector:customSelector:aaaID]; this part is not allows in objective-C.
Thanks