Reputation: 1902
In source code of the NSTask I've found interesting place in method waitUntilExit:
- (void) waitUntilExit
{
NSTimer *timer = nil;
while ([self isRunning])
{
NSDate *limit = [[NSDate alloc] initWithTimeIntervalSinceNow: 0.1];
if (timer == nil)
{
timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
target: nil
selector: @selector(class)
userInfo: nil
repeats: YES];
}
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: limit];
RELEASE(limit);
}
[timer invalidate];
}
I can't understand purpose of NSTimer here. And whose method class will be called?
Upvotes: 1
Views: 104
Reputation: 539955
The timer target is nil
, so the selector is actually irrelevant: You can send any message to nil
which is then simply discarded.
The compiler only verifies that the selector refers to some known method, in this case the class
method of the NSObject
protocol.
This dummy timer is necessary for the following runMode
statement
which otherwise could terminate immediately, as the NSRunLoop
documentation states:
If no input sources or timers are attached to the run loop, this method exits immediately and returns NO; otherwise.
Upvotes: 1