Im writing a little command line tool that use AFHTTPNetworkng to pull some data from a server and display it. However because AFHTTPNetwotking uses an asynchronous call back, the application exits prior to getting the response from the server. I there for added
NSRunLoop *run = [NSRunLoop currentRunLoop];
_timer = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(check) userInfo:nil repeats:YES];
[run addTimer:_timer forMode:NSDefaultRunLoopMode];
[run runUntilDate:[NSDate distantFuture]];
this timer calls a check method that checks to see if a BOOL has been set to yes (This happens in the call back). If it has it invalidates the timer.
- (void)check{
NSLog(@"checking");
if (test == YES) {
[_timer invalidate];
}
return;
}
This code works fine but now the app does not terminate, suggesting that the runloop is still running. I could use exit() to kill the app but this does not seem acceptable as this may cause a memory leak.