Created
February 21, 2012 16:23
-
-
Save vibrazy/1877241 to your computer and use it in GitHub Desktop.
NSArray Category
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
// | |
// NSArray_NSArrayUtils.h | |
// GCDAndBlocks | |
// | |
// Created by Daniel Hollis on 21/02/2012. | |
// Copyright (c) 2012 Mobile Interactive Group. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#ifdef DEBUG | |
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); | |
#else | |
# define DLog(...) | |
#endif | |
//ALog always displays output regardless of the DEBUG setting | |
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); | |
@interface NSArray (Utils) | |
-(id)safeObjectAtIndex:(NSUInteger)integer; | |
@end | |
@implementation NSArray (Utils) | |
-(id)safeObjectAtIndex:(NSUInteger)integer | |
{ | |
if (__builtin_expect(([self count] > integer),1)) { | |
return [self objectAtIndex:integer]; | |
} else { | |
NSArray *syms = [NSThread callStackSymbols]; | |
if ([syms count] > 1) { | |
DLog(@"<%@ %p> %@ - caller: %@ ", [self class], self, NSStringFromSelector(_cmd),[syms objectAtIndex:1]); | |
} else { | |
DLog(@"<%@ %p> %@", [self class], self, NSStringFromSelector(_cmd)); | |
} | |
#ifdef DEBUG | |
@throw [NSException exceptionWithName:@"MIG: Index Out Of Bounds" reason:@"Array stack not big enough for index" userInfo:nil]; | |
#endif | |
} | |
return nil; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment