有时 Cocoa 允许用户将 NSOperationQueue 或 dispath_queue_t 传递给 async 方法:
+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
-[AVPlayer addBoundaryTimeObserverForTimes:queue:usingBlock:]
-[NSNotificationCenter addObserverForName:object:queue:usingBlock:]
有时不会:
-[NSDocument continueActivityUsingBlock:]
-[NSSavePanel beginWithCompletionHandler:]
-[GKAchievementDescription loadImageWithCompletionHandler:]
对我来说,将队列传递给方法看起来很模糊,因为在创建块时总是可以捕获所需的队列。例如:
NSOperationQueue *q = …;
[aDocument continueActivityUsingBlock:^{
[q addOperationWithBlock:^{
// Do actual work here.
}];
}];
也许我错过了一些东西并且通过队列是有意义的?