Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSArray *myColors = @[@"Red", @"Green", @"Blue", @"Yellow"];
- // Fast enumeration
- // myColors cannot be modified inside the loop
- for (NSString *color in myColors) {
- NSLog(@"Element %@", color);
- }
- // Using indices
- for (NSUInteger i = 0; i < myColors.count; i++) {
- NSLog(@"Element %d = %@", i, myColors[i]);
- }
- // Using block enumeration
- [myColors enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL * stop) {
- NSLog(@"Element %d = %@", idx, obj);
- // To abort use:
- *stop = YES
- }];
- // Using block enumeration with options
- [myColors enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL * stop) {
- NSLog(@"Element %d = %@", idx, obj);
- }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement