标签:遍历数组 遍历字典 nsdictionary nsarray
1.遍历字典 NSDictionary *dictionary = @{@"name": @"jack", @"age": @"18"}; 1>for (NSString *key in dictionary) { id obj = dictionary[key]; } 2>NSArray *keyArray = [dictionary allKeys]; NSArray *valueArray = [dictionary allValues]; for (NSString *key in keyArray) { id obj = valueArray[key]; } 3>[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { *stop = YES; }]; 2.遍历数组 NSArray *array = @[@"jack", @"lucy"]; 1>for (NSString *str in array) { } 2>[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { }]; 3>迭代器遍历数组 NSEnumerator *enumerator = [array objectEnumerator]; [enumerator allObjects];//有值 id obj = nil; while (obj = [enumerator nextObject]) { } [enumerator allObjects];//返回nil
标签:遍历数组 遍历字典 nsdictionary nsarray
原文地址:http://blog.csdn.net/u014656271/article/details/44348213