Created
February 22, 2012 00:45
-
-
Save plantpurecode/1880242 to your computer and use it in GitHub Desktop.
Safe -objectAtIndex: method
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 NSArray (JRAdditions) | |
- (id) safeObjectAtIndex:(NSUInteger)index; | |
@end | |
@implementation NSArray (JRAdditions) | |
- (id) safeObjectAtIndex:(NSUInteger)index { | |
@synchronized(self) { | |
if(index >= [self count]) return nil; | |
return [self objectAtIndex:index]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment