tags:

views:

67

answers:

2

Hi all, I used NSRunloop in my application. While going from my current controller i need to exit from the run loop also. How can i exit from current run loop .

Runloop is implemented as follows.

while(!completed) {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];//[NSDate distantFuture]
}

Thanks in advance..

A: 

Here's what I've got in one of my projects. Seems to be working....

do {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (!finished);
Staros
A: 

To kill the run loop within the loop, you have to use CoreFoundation:

CFRunLoopStop(CFRunLoopGetCurrent());

Better, as stated in the manual of -runMode:beforeDate:

… it returns after either the first input source is processed or limitDate is reached …

So you could install an input source (CFRunLoopSource) to the run loop, and fire it when you're done.

KennyTM