Skip to content

Instantly share code, notes, and snippets.

@flexaddicted
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flexaddicted/11349249 to your computer and use it in GitHub Desktop.
Save flexaddicted/11349249 to your computer and use it in GitHub Desktop.
Extending NSManagedObject classes - Part 2
// CDBaseManagedObject.h
@interface CDBaseManagedObject : NSManagedObject
+ (NSString *)entityName;
+ (instancetype)insertNewObjectIntoContext:(NSManagedObjectContext *)context;
@end
// CDBaseManagedObject.m
@implementation CDBaseManagedObject
+ (NSString *)entityName {
return NSStringFromClass(self);
}
+ (instancetype)insertNewObjectIntoContext:(NSManagedObjectContext *)context {
return [NSEntityDescription insertNewObjectForEntityForName:[self entityName] inManagedObjectContext:context];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment