Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created January 28, 2013 13:31
Show Gist options
  • Save lukeredpath/4655514 to your computer and use it in GitHub Desktop.
Save lukeredpath/4655514 to your computer and use it in GitHub Desktop.
/* Allows you to give a context a descriptive name to aid in
* debugging.
*/
@interface NSManagedObjectContext (DescriptiveName)
@property (nonatomic, copy) NSString *descriptiveName;
@end
// 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