In Objective-C, a selector’s signature consists of:
- The name of the method (in this case it would be ‘myTest’) (required)
- A ‘;’ (colon) following the method name if the method has an input.
- A name and ‘:’ for every additional input.
Selectors have no knowledge of:
- The input types
- The method’s return type.
Here’s a class implementation where performMethodsViaSelectors method performs the other class methods by way of selectors:
@implementation ClassForSelectors - (void) fooNoInputs { NSLog(@"Does nothing"); } - (void) fooOneIput:(NSString*) first { NSLog(@"Logs %@", first); } - (void) fooFirstInput:(NSString*) first secondInput:(NSString*) second { NSLog(@"Logs %@ then %@", first, second); } - (void) performMethodsViaSelectors { [self performSelector:@selector(fooNoInputs)]; [self performSelector:@selector(fooOneInput:) withObject:@"first"]; [self performSelector:@selector(fooFirstInput:secondInput:) withObject:@"first" withObject:@"second"]; } @endThe method you want to create a selector for has a single input, so you would create a selector for it like so:
SEL myTestSelector = @selector(myTest:);via Objective-C: Calling selectors with multiple arguments – Stack Overflow.
Calling selectors with multiple arguments – Stack Overflow
Subscribe
Subscribe to our e-mail newsletter to receive updates.
No comments yet.