Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. NSArray *myColors = @[@"Red", @"Green", @"Blue", @"Yellow"];
  2.  
  3. // Fast enumeration
  4. // myColors cannot be modified inside the loop
  5. for (NSString *color in myColors) {
  6. NSLog(@"Element %@", color);
  7. }
  8.  
  9. // Using indices
  10. for (NSUInteger i = 0; i < myColors.count; i++) {
  11. NSLog(@"Element %d = %@", i, myColors[i]);
  12. }
  13.  
  14. // Using block enumeration
  15. [myColors enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL * stop) {
  16. NSLog(@"Element %d = %@", idx, obj);
  17.  
  18. // To abort use:
  19. *stop = YES
  20. }];
  21.  
  22. // Using block enumeration with options
  23. [myColors enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL * stop) {
  24. NSLog(@"Element %d = %@", idx, obj);
  25. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement