Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@interface MappedArray ()
@property (nonatomic) NSArray *backingArray;
@end
@implementation MappedArray
- (instancetype)initWithArray:(NSArray *)array transformationBlock:(id (^)(id object))block {
self = [super init];
if (!self) return nil;
NSMutableArray *mappedArray = [NSMutableArray arrayWithCapacity:array.count];
for (NSInteger i = 0; i < array.count; i++) {
[mappedArray addObject:block(array[i]) ?: [NSNull null]];
}
_backingArray = [mappedArray copy];
return self;
}
- (NSUInteger)count {
return self.backingArray.count;
}
- (id)objectAtIndex:(NSUInteger)index {
return [self.backingArray objectAtIndex:index];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.