Skip to content

Instantly share code, notes, and snippets.

@flexaddicted
Created February 22, 2015 13:35
Show Gist options
  • Select an option

  • Save flexaddicted/10017c7856a741320fb4 to your computer and use it in GitHub Desktop.

Select an option

Save flexaddicted/10017c7856a741320fb4 to your computer and use it in GitHub Desktop.
// 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