Question

The Problem

I run my unit tests. At one point, I wait using:

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];

for an NSOperationQueue to be empty. When my app reaches this line, it terminates immediately. It's run this exact same line with other tests. All tests were working perfectly recently. It also sometimes terminates my app on startup immediately.

What on earth is going on?

Was it helpful?

Solution

I've posted this for me to provide an answer in case others run into the same problem, as I've spent a full day on this and thanks to the awesomeness of git, have finally tracked down the issue.

I added:

-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
    return YES;
}

into my app delegate as I wanted my app to terminate on window close. It turns out that this is the cause of the apparently random termination.

I do hide my window on startup, so I can only think this is what's causing the app to terminate immediately, although this doesn't happen every time on launch of the actual app.

I just know it was terminating consistently on that unit test, which made me think it was something to do with this code or my test. It wasn't.

I got rid of the above line and now everything works as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top