void FastEnumration(){
NSArray *array = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"];
//一坐儿、For Statement
for (int i = 0 ; i<array.count; i++) {
NSLog(@"for statement %@---%@",array[i],[NSThread currentThread]);
}
//二、快速排序
for (NSString *str in array) {
NSLog(@"for fast enumration %@---%@",str,[NSThread currentThread]);
}
//三宋光、NSEnumerator
NSEnumerator *enumer=[array objectEnumerator];
id obj;
while (obj=[enumer nextObject]) {
NSLog(@"objectEnumerator %@----%@",obj,[NSThread currentThread]);
}
//四貌矿、enumerateObjectsUsingBlock
//順序遍歷
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"順序遍歷 %@----%@",array[idx],[NSThread currentThread]);
}];
//倒序遍歷
[array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"倒序遍歷 %@----%@",array[idx],[NSThread currentThread]);
}];
//五、快速迭代
//將block中的任務(wù)罪佳,逐個(gè)放到queue中站叼,然后進(jìn)行dispatch_sync執(zhí)行
//多線程同步循環(huán)
dispatch_queue_t queue =dispatch_queue_create("apply并行隊(duì)列", DISPATCH_QUEUE_CONCURRENT);
dispatch_apply([array count], queue, ^(size_t index) {
NSLog(@"%@----%@",array[index],[NSThread currentThread]);
});
}
總結(jié),從數(shù)據(jù)來(lái)看菇民,性能差異較小尽楔,所以大家視使用場(chǎng)景,自行決定使用哪一個(gè)第练。(數(shù)據(jù)量較大時(shí)阔馋,更易看出,感興趣的請(qǐng)自行運(yùn)行代碼測(cè)試)再次申明:內(nèi)容是本人學(xué)習(xí)之互聯(lián)網(wǎng)娇掏,并做筆記之用呕寝。