一、
1.for in 比for高效.
2.enumerateObjectsUsingBlock和for in 效率差不多,enumerateObjectsUsingBlock有时候会比for in 快.
3.enumerateObjectsUsingBlock要修改局部变量的时候,局部变量要声明成__block类型.
4.CFAbsoluteTimeGetCurrent 获取当前时间,多用于函数的性能测试.
二、
- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(ObjectType obj, NSUInteger idx,BOOL *stop))block
其中opts包含两种类型:
NSEnumerationConcurrent = (1UL <<0),//并发,顺序不确定
NSEnumerationReverse = (1UL <<1),//倒叙,顺序确定
NSArray版
- (void)enumerateObjectsUsingBlock:(void (^)(ObjectType obj,NSUInteger idx, BOOL *stop))block
- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(ObjectType obj, NSUInteger idx,BOOL *stop))block
- (void)enumerateObjectsAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts usingBlock:(void (^)(ObjectType obj,NSUInteger idx,BOOL *stop))block
NSDictionary版
- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(KeyType key, ObjectType obj,BOOL *stop))block
- (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(KeyType key, ObjectType obj, BOOL *stop))block
NSDictionary *dict =@{@"one":@"Lily",@"tow":@"LiLei",@"three":@"Lucy"};
[dict enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key,id _Nonnull obj,BOOL *_Nonnull stop) {
NSLog(@"key%@,value%@",key,obj);
}];
http://www.cocoachina.com/industry/20140531/8630.html
http://www.cnblogs.com/skyming/p/3977075.html