slabko
2/8/2015 - 4:58 PM

NSArray from range

NSArray from range

#import "NSArray+ARLRange.h"

@implementation NSArray (ARLRange)

- (instancetype)initWithRange:(NSRange)range
{
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:range.length];
    for (NSUInteger i = range.location; i < NSMaxRange(range); ++i) {
        [array addObject:@(i)];
    }
    return [self initWithArray:array];
}

+ (instancetype)arrayWithRange:(NSRange)range
{
    return [[self alloc] initWithRange:range];
}

@end
#import <Foundation/Foundation.h>

#define NSRangeEnumerate(i, range) for(i = range.location; i < NSMaxRange(range); ++i)

@interface NSArray (ARLRange)

- (instancetype)initWithRange:(NSRange)range;
+ (instancetype)arrayWithRange:(NSRange)range;

@end