Stop an NSRunLoop

Makio picture Makio · Apr 25, 2013 · Viewed 7.2k times · Source

I have a connection in a thread, so I add it to the run loop to get all data:

  [[NSRunLoop currentRunLoop] run];
  [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

But I can't find any way to stop it

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    if([NSRunLoop currentRunLoop]){
        [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
    }
    [connection cancel];
}

How can I stop this loop?

Answer

hrchen picture hrchen · Jun 28, 2013

You can stop the runloop by Core Fundation API :

CFRunLoopStop(CFRunLoopGetCurrent());