From 0c9e6afe0e88fc0cfff919b5ed30d213b7b1cfe7 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Mon, 24 Aug 2015 17:33:27 +0900 Subject: [PATCH] added utility to inspect NSEntityDescription for a given NSManagedObject type --- .../Internal/NSManagedObjectModel+Setup.swift | 2 +- CoreStore/Setting Up/DataStack.swift | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CoreStore/Internal/NSManagedObjectModel+Setup.swift b/CoreStore/Internal/NSManagedObjectModel+Setup.swift index 8ddd4b5..ffd82e2 100644 --- a/CoreStore/Internal/NSManagedObjectModel+Setup.swift +++ b/CoreStore/Internal/NSManagedObjectModel+Setup.swift @@ -150,7 +150,7 @@ internal extension NSManagedObjectModel { return self.entityNameMapping[NSStringFromClass(entityClass)]! } - @nonobjc internal func entityMapping() -> [String: NSManagedObject.Type] { + @nonobjc internal func entityTypesMapping() -> [String: NSManagedObject.Type] { return self.entityNameMapping.reduce([:]) { (var mapping, pair) in diff --git a/CoreStore/Setting Up/DataStack.swift b/CoreStore/Setting Up/DataStack.swift index e435c0a..46fe6ce 100644 --- a/CoreStore/Setting Up/DataStack.swift +++ b/CoreStore/Setting Up/DataStack.swift @@ -84,9 +84,20 @@ public final class DataStack { /** Returns the entity name-to-class type mapping from the `DataStack`'s model. */ - public var entitiesByName: [String: NSManagedObject.Type] { + public var entityTypesByName: [String: NSManagedObject.Type] { - return self.model.entityMapping() + return self.model.entityTypesMapping() + } + + /** + Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass. + */ + public func entityDescriptionForType(type: NSManagedObject.Type) -> NSEntityDescription? { + + return NSEntityDescription.entityForName( + self.model.entityNameForClass(type), + inManagedObjectContext: self.mainContext + ) } /**