iOS NSEnumerator

{
// NSEnumerator示例 //反向获取数组
NSArray array= [NSArray arrayWithObjects:@"112",@"234",@"3434",@"3455" ,nil];
/

NSEnumerator *enumerator = [array reverseObjectEnumerator];//反向获取数组
NSLog(@"%@",enumerator);

    id thing;
    while (thing = [enumerator nextObject]) {//下一个对象:nextObject
        NSLog(@"Ifound %@",thing);
    }

// NSArray *arr = [enumerator allObjects];
// for (NSString *res in arr) {
// NSLog(@"%@",res);
// }
*/

    //按照数组的顺序
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSLog(@"&&wgj:v:%@:\t%ld",obj, idx);
    }];
    //数组的反向
    [array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSLog(@"\\\\nv:%@:\t%ld",obj, idx);
    }];
    //随机的打印
    [array enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSLog(@"\\\\nv:%@:\t%ld",obj, idx);
    }];
    
    for (id ob in array) {
        NSLog(@"***for:%@-%ld",ob, [array indexOfObject:ob]);
    }
}

你可能感兴趣的:(iOS NSEnumerator)