Advertisement
ZaBlanc

Kata 9/23 Block Methods

Sep 23rd, 2011
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. typedef NSInteger (^ib_enum_bool_t)(id);
  2. typedef id (^ib_enum_id_t)(id);
  3.  
  4. - (void)deleteIf:(ib_enum_bool_t)blk {
  5.     for (NSInteger i = (self.count - 1); i >= 0; --i) {
  6.         if (blk([self objectAtIndex:i])) {
  7.             [self removeObjectAtIndex:i];
  8.         }
  9.     }
  10. }
  11.  
  12. - (NSArray *)map:(ib_enum_id_t)blk {
  13.     NSMutableArray *mappedArray = [NSMutableArray array];
  14.    
  15.     for (NSInteger i = (self.count - 1); i >= 0; --i) {
  16.         [mappedArray unshiftObject:blk([self objectAtIndex:i])];
  17.     }
  18.    
  19.     return mappedArray;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement