Created
February 8, 2015 16:58
-
-
Save slabko/6db4181a3411dfd9d3dc to your computer and use it in GitHub Desktop.
NSArray from range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment