Created
July 12, 2012 06:50
-
-
Save skahack/3096340 to your computer and use it in GitHub Desktop.
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
@interface Range : NSObject <NSFastEnumeration> | |
@property (readwrite, nonatomic, retain) NSNumber *start; | |
@property (readwrite, nonatomic, retain) NSNumber *end; | |
+ (Range *)createWithStart:(NSUInteger)start End:(NSUInteger)end; | |
- (id)initWithStart:(NSUInteger)start End:(NSUInteger)end; | |
@end | |
@implementation Range | |
@synthesize start = _start; | |
@synthesize end = _end; | |
+ (Range *)createWithStart:(NSUInteger)s End:(NSUInteger)e { | |
return [[[self alloc] initWithStart:s End:e] autorelease]; | |
} | |
- (id)initWithStart:(NSUInteger)s End:(NSUInteger)e { | |
self = [super init]; | |
if (!self) { | |
return nil; | |
} | |
self.start = [NSNumber numberWithInteger:s]; | |
self.end = [NSNumber numberWithInteger:e]; | |
return self; | |
} | |
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len { | |
NSInteger size = [_end intValue] - [_start intValue]; | |
if (state->state >= size) { | |
return 0; | |
} | |
NSInteger count = 0; | |
while (state->state < size && count < len) { | |
stackbuf[count] = [NSNumber numberWithUnsignedLong:state->state]; | |
state->state++; | |
count++; | |
} | |
state->itemsPtr = stackbuf; | |
state->mutationsPtr = (unsigned long*)self; | |
return count; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment