smart way to load entityNames from the model file

This commit is contained in:
John Rommel Estropia
2015-02-22 22:01:23 +09:00
parent f6ced13577
commit 8f77818015
8 changed files with 88 additions and 44 deletions

View File

@@ -31,21 +31,14 @@ import CoreData
extension NSManagedObject {
// MARK: - Entity Utilities
public class var entityName: String {
// TODO: map from model file
return NSStringFromClass(self).componentsSeparatedByString(".").last!
}
// MARK: - Internal
internal class func createInContext(context: NSManagedObjectContext) -> Self {
return self(entity: NSEntityDescription.entityForName(self.entityName, inManagedObjectContext: context)!,
insertIntoManagedObjectContext: context)
return self(
entity: context.entityDescriptionForEntityClass(self)!,
insertIntoManagedObjectContext: context
)
}
internal func inContext(context: NSManagedObjectContext) -> Self? {