How to create an "array of selectors"
Why not just use a simple C array?
static const SEL selectors[] = {@selector(method1),
....
@selector(method7)};
...
for (int i = 0; i < sizeof(selectors)/sizeof(selectors[0]); i++) {
[self performSelector:selectors[i]];
// ....
}
This creates an object out of selector:
[NSValue valueWithPointer:@selector(x)]
Could you store strings and use NSSelectorFromString?
From the docs
NSSelectorFromString
Returns the selector with a given name.
SEL NSSelectorFromString (
NSString *aSelectorName
);
You can also create an array of NSInvocation
s. This is handy if you need an argument to go with your selector.
NSMethodSignature *sig = [[yourTarget class] instanceMethodSignatureForSelector:yourSEL];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:yourTarget];
[inv setSelector:yourSEL];
[inv setArgument:&yourObject atIndex:2]; // Address of your object