Skip to content

Instantly share code, notes, and snippets.

@slembcke
Created June 8, 2012 23:01
Show Gist options
  • Save slembcke/2898561 to your computer and use it in GitHub Desktop.
Save slembcke/2898561 to your computer and use it in GitHub Desktop.
NotCrappyAssertionHandler
@interface NotCrappyAssertionHandler : NSAssertionHandler @end
@implementation NotCrappyAssertionHandler
-(void)handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format, ...
{
NSLog(@"*** Assertion failure in %@(), %@:%d", functionName, fileName, line);
va_list args;
va_start(args, format);
NSLogv([@"*** Assertion message: " stringByAppendingString:format], args);
va_end(args);
abort();
}
-(void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format, ...
{
NSString *class = NSStringFromClass([object class]);
NSString *method = NSStringFromSelector(selector);
NSString *formattedMethod = [NSString stringWithFormat:@"%@[%@ %@]", (object == [object class] ? @"+" : @"-"), class, method];
NSLog(@"*** Assertion failure in %@, %@:%d", formattedMethod, fileName, line);
va_list args;
va_start(args, format);
NSLogv([@"*** Assertion message: " stringByAppendingString:format], args);
va_end(args);
abort();
}
@end
// You install the handler by calling this in the applicationDidFinishLaunching: method or similar:
[[[NSThread currentThread] threadDictionary] setObject:[[NotCrappyAssertionHandler alloc] init] forKey:NSAssertionHandlerKey];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment