I have an array of methods I have to fire in sequence. Every method returns a BOOL. Something like
- (BOOL) oneMethod;
The method names are on an array like
#define TESTS @[ \
@"averageNotOK:", \
@"numbersOverRange:", \
@"numbersUnderRange:",\
@"numbersForbidden:", \
// ... etc etc
@"numbersNotOnCurve:"]
The methods run in a loop. Something like
- (BOOL) numbersPassedAllTests:(NSArray *)numbers {
NSInteger count = [TESTS count];
for (int i=0; i<count; i++) {
NSString *aMethodName = TESTS[i];
SEL selector = NSSelectorFromString(aMethodName);
BOOL failed = NO;
NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
[invocation setTarget:self];
[invocation setArgument:&numbers atIndex:2];
[invocation invoke];
[invocation getReturnValue:&failed];
if (failed) {
return NO;
}
}
return YES;
}
Is there a way to run these methods without using NSInvocation?
Yes, I need the methods on an array of strings (not array of selectors), because I need their names on other contexts. I know that I cannot use performSelector because it returns void and I need something to return BOOL. Yes, I know about an extension for performSelector that returns anything, but it uses NSInvocation and I am trying to discover another method to do this without using NSInvocation.
Any ideas?