Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specifying @selector for method on another object?

Quick question, is there a way to specify a @selector that is a method on another object. Currently I have fudged a solution by using a local method to call the remote method, but it feels clunky.

[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timerLocation) userInfo:nil repeats:YES]];

.

- (void)timerLocation {
    [[self dataModel] startUpdatingLocation];
}
like image 952
fuzzygoat Avatar asked Feb 25 '11 14:02

fuzzygoat


2 Answers

That's what the target portion of the NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: method is for. (i.e.: You specify the object you want to call as the target and the name of the object's method as the selector.)

like image 178
John Parker Avatar answered Sep 26 '22 18:09

John Parker


[NSTimer scheduledTimerWithTimeInterval:10 target:someOtherObject selector:@selector(timerLocation) userInfo:nil repeats:YES];
like image 32
Sorig Avatar answered Sep 25 '22 18:09

Sorig