So, I’m trying to call a method in another object and pass the calling object as part of the call. Could be the way I’m architecting it just makes no sense, but anyway here’s the call:
NSTimer *refreshTimer = [NSTimer
scheduledTimerWithTimeInterval:[timerDate timeIntervalSinceNow]
target:otherObject
selector:@selector(methodBeingCalled:self)
userInfo:nil
repeats:NO];
And the receiving method has the following signature:
- (void)methodBeingCalled:(id)sender;
When I do this, I get an error on the call that says, “Error expected ‘:'”. Which doesn’t make sense to me, because I’ve got a colon in there to pass “self” as a parameter.
Am I using the selector incorrectly? Should I be using an NSInvocation instead?
You don’t get to set the parameters like that. A selector only defines the signature and how many arguments a function has. Remove
self, because you can’t send it. If you want to passself, do it inuserInfo. The object that will come in anNSTimermethod is theNSTimeritself.P.S. Documentation is your friend. It clearly states there (for the selector argument) that “The selector must correspond to a method that returns void and takes a single argument. The timer passes itself as the argument to this method.”