Skip to content

Instantly share code, notes, and snippets.

@plantpurecode
Created February 22, 2012 00:45
Show Gist options
  • Save plantpurecode/1880242 to your computer and use it in GitHub Desktop.
Save plantpurecode/1880242 to your computer and use it in GitHub Desktop.
Safe -objectAtIndex: method
@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