我知道获取操作队列的两种方法如下:
queue1 = [[NSOperationQueue alloc] init];
queue2 = [[NSOperationQueue mainQueue] retain];
但我不知道它们之间有什么区别。
[queue1 addOperation:operation1];
[queue2 addOperation:operation2];
operation1 在哪个线程上运行?主线程?或不确定性?
我测试过。
operation1 --> sometimes mainthread sometimes not.
operation2 --> always mainthread.
最佳答案
According to the documentation NSOperationQueue 的:
create separate threads for non-concurrent operations and launch concurrent operations from the current thread.
这解释了为什么您的一些任务在主线程上运行而其他任务不运行。
mainQueue
绑定(bind)到主线程,所以操作总是在主线程上执行。
关于iOS开发关于NSOperationQueue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7736455/