Guest User

Untitled

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. //
  2. // NSArray+DSLFirstItems.m
  3. //
  4. // Created by Pete Callaway on 15/10/2010.
  5. // Copyright 2010 Dative Studios. All rights reserved.
  6. // Modified by Abizer Nasir
  7. //
  8.  
  9. #import "NSArray+DSLFirstItems.h"
  10.  
  11.  
  12. @implementation NSArray (DSLFirstItems)
  13.  
  14. - (void)dsl_enumerateUpTo:(NSUInteger)numberOfItemsToEnumerate inDirection:(DSLEnumerationOption)direction usingBlock:(DSLFirstItemWorkBlock)block {
  15. NSInteger count = 0;
  16. BOOL stop = NO;
  17.  
  18. id <NSFastEnumeration> iterable;
  19.  
  20. if (direction == DSLEnumerationForward) {
  21. iterable = self;
  22. } else {
  23. iterable = [self reverseObjectEnumerator];
  24. }
  25.  
  26. for (id object in iterable) {
  27. block(object, count, &stop);
  28.  
  29. if (stop) return;
  30.  
  31. count++;
  32. if (count >= numberOfItemsToEnumerate) return;
  33. }
  34. }
  35.  
  36. @end
Add Comment
Please, Sign In to add comment