我有这段代码:
dispatch_queue_t queue = dispatch_queue_create("Queue", NULL);
dispatch_async(queue, ^{
//accessing the internet
dispatch_sync(dispatch_get_main_queue(), ^{
[myObject myFunction];
});
});
在 myFunction 中:
dispatch_queue_t queue = dispatch_queue_create("anotherQueue", NULL);
dispatch_async(queue, ^{
//long task that takes seconds
dispatch_sync(dispatch_get_main_queue(), ^{
//this is never executed
NSLog(@"Got to main thread.");
//updating the UI
});
});
有人可以解释为什么块 ^{ NSLog(@"Got to main thread."); }); 不被执行?