Created
May 18, 2012 13:39
-
-
Save AlanQuatermain/2725326 to your computer and use it in GitHub Desktop.
A non-zero-based array. Guess what base it uses-- it could be anything!
This file contains 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 AQNonZeroBasedArray : NSArray | |
@end | |
@implementation AQNonZeroBasedArray | |
{ | |
NSArray * _realArray; | |
NSUInteger _base; | |
} | |
// initialize it using AQNonZeroBasedArray * array = @[obj1, obj2, obj3]; | |
- (id) initWithObjects: (id __unsafe_unretained []) objects count: (NSUInteger) count | |
{ | |
self = [super init]; | |
if ( self == nil ) | |
return ( nil ); | |
_realArray = [[NSArray alloc] initWithObjects: objects count: count]; | |
_base = arc4random() % 100; // yeah, I'm not TOTALLY evil... | |
return ( self ); | |
} | |
- (NSUInteger) count | |
{ | |
return ( [_realArray count] ); | |
} | |
- (id) objectAtIndex: (NSUInteger) index | |
{ | |
index -= _base; | |
if ( NSLocationInRange(index, NSMakeRange(0, [_realArray count])) == NO ) | |
[NSException raise: @"AQNonZeroBaseSurpriseException" format: @"HAHA LOLWUT!?"]; | |
return ( [_realArray objectAtIndex: index] ); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment