Created
June 8, 2012 23:01
-
-
Save slembcke/2898561 to your computer and use it in GitHub Desktop.
NotCrappyAssertionHandler
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 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