Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 47 lines (40 sloc) 1.036 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
//
// NSArray+BBExtensions.m
// BBOSC
//
// Created by Jonathan del Strother on 09/09/2009.
// Copyright 2009 Best Before Media Ltd. All rights reserved.
//

#import "NSArray+BBExtensions.h"


@implementation NSArray(BBExtensions)
- (NSArray *)map: (id (^)(id obj))block
{
NSMutableArray *new = [NSMutableArray array];
for(id obj in self)
{
id newObj = block(obj);
[new addObject: newObj ? newObj : [NSNull null]];
}
return new;
}


- (NSArray *)select: (BOOL (^)(id obj))block
{
NSMutableArray *new = [NSMutableArray array];
for(id obj in self)
{
BOOL selected = block(obj);
if (selected)
[new addObject:obj];
}
return new;
}

-(NSDictionary*)qcStructure {
    NSMutableDictionary* result = [NSMutableDictionary dictionaryWithCapacity:self.count];
    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSString* key = [[NSString alloc] initWithFormat:@"%d", (unsigned long)idx];
        [result setObject:obj forKey:key];
        [key release];
    }];
    return result;
}
@end
Something went wrong with that request. Please try again.