Search code examples
cocoacss-selectorsfoundationnsrange

syntax of @selector


ok without using NSInvocation, let's say I have this code:

...
array = [NSMutableArray arrayWithObjects:@"Yoda", @"Jedi", @"Darth Vader", @"Darth Vader", @"Darth Vader" , @"Darth Vader", nil];

SEL removeObjectMessage = @selector(removeObject:inRange:);

//does array allow us to remove and object in a range? if so let's do this    
if ([array respondsToSelector:removeObjectMessage]){   
    NSRange darthVaderRange=NSMakeRange(2, 3);
    [array removeObject:@"Darth Vader"inRange:darthVaderRange];
}

how would I perform that last line in the form of the SEL removeObjectMessage? I would have to put a wrapper around the range? I just want to see the syntax of how all that mess would look...


Solution

  • Unfortunately, if you're passing an argument that's not of type id, you have to use an NSInvocation object. (Otherwise, you could use performSelector:withObject:withObject:.)