Created
January 28, 2013 13:31
-
-
Save lukeredpath/4655514 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* Allows you to give a context a descriptive name to aid in | |
* debugging. | |
*/ | |
@interface NSManagedObjectContext (DescriptiveName) | |
@property (nonatomic, copy) NSString *descriptiveName; | |
@end |
This file contains hidden or 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
// Using .mm to fool gist into thinking its Objective-C - this isn't Objective-C++! | |
@implementation NSManagedObjectContext (DescriptiveName) | |
- (void)setDescriptiveName:(NSString *)descriptiveName | |
{ | |
[self.userInfo setObject:descriptiveName forKey:@"descriptive-name"]; | |
} | |
- (NSString *)descriptiveName | |
{ | |
return [self.userInfo objectForKey:@"descriptive-name"]; | |
} | |
- (NSString *)description | |
{ | |
if (self.descriptiveName) { | |
NSString *className = NSStringFromClass(self.class); | |
return [[super description] stringByReplacingOccurrencesOfString:className withString:[NSString stringWithFormat:@"%@(%@)", className, self.descriptiveName]]; | |
} | |
return [super description]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment