NSOperationQueue的maxConcurrentOperationCount属性
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NSOperationQueue的maxConcurrentOperationCount属性相关的知识,希望对你有一定的参考价值。
代码:
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; queue.maxConcurrentOperationCount = 2; for (NSUInteger i = 1; i <= 10; ++i) { [queue addOperationWithBlock:^{ NSLog(@"Block %lu", i); [NSThread sleepForTimeInterval:1]; }]; }
输出:
2016-11-03 22:20:37.508 maxConcurrentOperationCount[1196:26292] Block 1 2016-11-03 22:20:37.508 maxConcurrentOperationCount[1196:26295] Block 2 2016-11-03 22:20:38.512 maxConcurrentOperationCount[1196:26290] Block 3 2016-11-03 22:20:38.512 maxConcurrentOperationCount[1196:26295] Block 4 2016-11-03 22:20:39.517 maxConcurrentOperationCount[1196:26292] Block 5 2016-11-03 22:20:39.517 maxConcurrentOperationCount[1196:26290] Block 6 2016-11-03 22:20:40.523 maxConcurrentOperationCount[1196:26290] Block 8 2016-11-03 22:20:40.523 maxConcurrentOperationCount[1196:26295] Block 7 2016-11-03 22:20:41.525 maxConcurrentOperationCount[1196:26290] Block 9 2016-11-03 22:20:41.525 maxConcurrentOperationCount[1196:26292] Block 10
备注:
请注意每两行输出之间的时间间隔
以上是关于NSOperationQueue的maxConcurrentOperationCount属性的主要内容,如果未能解决你的问题,请参考以下文章