Grand Central Dispatch and unit testing
问题 I have written a simple test case that follows Apple's documentation and I am not seeing the results that I'm expecting. Here's the code: - (void)testExample2 { NSLog(@"1"); dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"3"); dispatch_semaphore_signal(semaphore); }); NSLog(@"2"); dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); NSLog(@"4"); dispatch_release(semaphore); } I would expect to read: 1, 2, 3, 4 but