Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
@interface MappedArray ()
@property (nonatomic) NSArray *backingArray;
@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];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment