WIP: prototype for ManagedObjectProtocol

This commit is contained in:
John Estropia
2017-04-05 21:56:19 +09:00
parent 258c237100
commit 8b77e4e5a0
44 changed files with 1244 additions and 823 deletions

View File

@@ -44,21 +44,9 @@ public extension CSCoreStore {
Returns the entity name-to-class type mapping from the `defaultStack`'s model.
*/
@objc
public static var entityClassesByName: [String: NSManagedObject.Type] {
public static func entityTypesByNameForType(_ type: NSManagedObject.Type) -> [EntityName: NSManagedObject.Type] {
return CoreStore.entityTypesByName
}
/**
Returns the entity class for the given entity name from the `defaultStack`'s model.
- parameter name: the entity name
- returns: the `NSManagedObject` class for the given entity name, or `nil` if not found
*/
@objc
public static func entityClassWithName(_ name: String) -> NSManagedObject.Type? {
return CoreStore.entityTypesByName[name]
return CoreStore.entityTypesByName(for: type)
}
/**
@@ -137,4 +125,30 @@ public extension CSCoreStore {
return self.defaultStack.addSQLiteStorageAndWait(storage, error: error)
}
// MARK: Deprecated
/**
Returns the entity name-to-class type mapping from the `defaultStack`'s model.
*/
@available(*, deprecated: 3.1, message: "Use the new +entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public static var entityClassesByName: [EntityName: NSManagedObject.Type] {
return CoreStore.entityTypesByName
}
/**
Returns the entity class for the given entity name from the `defaultStack`'s model.
- parameter name: the entity name
- returns: the `NSManagedObject` class for the given entity name, or `nil` if not found
*/
@available(*, deprecated: 3.1, message: "Use the new +entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public static func entityClassWithName(_ name: EntityName) -> NSManagedObject.Type? {
return CoreStore.entityTypesByName[name]
}
}

View File

@@ -54,7 +54,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
- parameter versionChain: the version strings that indicate the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
*/
@objc
public convenience init(modelName: String?, bundle: Bundle?, versionChain: [String]?) {
public convenience init(modelName: XcdatamodelFilename?, bundle: Bundle?, versionChain: [String]?) {
self.init(
DataStack(
@@ -73,7 +73,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
- parameter versionTree: the version strings that indicate the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
*/
@objc
public convenience init(modelName: String?, bundle: Bundle?, versionTree: [String: String]?) {
public convenience init(modelName: XcdatamodelFilename?, bundle: Bundle?, versionTree: [String: String]?) {
self.init(
DataStack(
@@ -128,23 +128,12 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
}
/**
Returns the entity name-to-class type mapping from the stack's model.
Returns the entity name-to-class type mapping from the `CSDataStack`'s model.
*/
@objc
public var entityClassesByName: [String: NSManagedObject.Type] {
public func entityTypesByNameForType(_ type: NSManagedObject.Type) -> [EntityName: NSManagedObject.Type] {
return self.bridgeToSwift.entityTypesByName
}
/**
Returns the entity class for the given entity name from the stack's's model.
- parameter name: the entity name
- returns: the `NSManagedObject` class for the given entity name, or `nil` if not found
*/
@objc
public func entityClassWithName(_ name: String) -> NSManagedObject.Type? {
return self.bridgeToSwift.entityTypesByName[name]
return self.bridgeToSwift.entityTypesByName(for: type)
}
/**
@@ -268,6 +257,31 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
self.bridgeToSwift = swiftValue
super.init()
}
// MARK: Deprecated
/**
Returns the entity name-to-class type mapping from the stack's model.
*/
@available(*, deprecated: 3.1, message: "Use the new -entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public var entityClassesByName: [EntityName: NSManagedObject.Type] {
return self.bridgeToSwift.entityTypesByName
}
/**
Returns the entity class for the given entity name from the stack's's model.
- parameter name: the entity name
- returns: the `NSManagedObject` class for the given entity name, or `nil` if not found
*/
@available(*, deprecated: 3.1, message: "Use the new -entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public func entityClassWithName(_ name: EntityName) -> NSManagedObject.Type? {
return self.bridgeToSwift.entityTypesByName[name]
}
}

View File

@@ -35,7 +35,7 @@ import CoreData
- SeeAlso: `From`
*/
@objc
public final class CSFrom: NSObject, CoreStoreObjectiveCType {
public final class CSFrom: NSObject {
/**
The associated `NSManagedObject` entity class
@@ -71,7 +71,7 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
- parameter entityClass: the `NSManagedObject` class type to be created
*/
@objc
public convenience init(entityClass: AnyClass) {
public convenience init(entityClass: NSManagedObject.Type) {
self.init(From(entityClass))
}
@@ -85,7 +85,7 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `[NSNull null]` to use the default configuration.
*/
@objc
public convenience init(entityClass: AnyClass, configuration: Any) {
public convenience init(entityClass: NSManagedObject.Type, configuration: Any) {
switch configuration {
@@ -111,9 +111,9 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
- parameter configurations: an array of the `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `[NSNull null]` to use the default configuration.
*/
@objc
public convenience init(entityClass: AnyClass, configurations: [Any]) {
public convenience init(entityClass: NSManagedObject.Type, configurations: [Any]) {
var arguments = [String?]()
var arguments = [ModelConfiguration]()
for configuration in configurations {
switch configuration {
@@ -154,7 +154,7 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
// MARK: - From
extension From: CoreStoreSwiftType {
extension From where T: NSManagedObject {
// MARK: CoreStoreSwiftType
@@ -162,4 +162,16 @@ extension From: CoreStoreSwiftType {
return CSFrom(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> From<NSManagedObject> {
return From<NSManagedObject>(
entityClass: self.entityClass,
configurations: self.configurations,
findPersistentStores: self.findPersistentStores
)
}
}

View File

@@ -43,7 +43,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjec
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration.
*/
@objc
public convenience init(configuration: String?) {
public convenience init(configuration: ModelConfiguration) {
self.init(InMemoryStore(configuration: configuration))
}
@@ -70,7 +70,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjec
The configuration name in the model file
*/
@objc
public var configuration: String? {
public var configuration: ModelConfiguration {
return self.bridgeToSwift.configuration
}

View File

@@ -35,13 +35,13 @@ import CoreData
- SeeAlso: `Into`
*/
@objc
public final class CSInto: NSObject, CoreStoreObjectiveCType {
public final class CSInto: NSObject {
/**
The associated `NSManagedObject` entity class
*/
@objc
public var entityClass: AnyClass {
public var entityClass: NSManagedObject.Type {
return self.bridgeToSwift.entityClass
}
@@ -51,7 +51,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType {
May contain a `String` to pertain to a named configuration, or `nil` to pertain to the default configuration
*/
@objc
public var configuration: String? {
public var configuration: ModelConfiguration {
return self.bridgeToSwift.configuration
}
@@ -65,7 +65,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType {
- parameter entityClass: the `NSManagedObject` class type to be created
*/
@objc
public convenience init(entityClass: AnyClass) {
public convenience init(entityClass: NSManagedObject.Type) {
self.init(Into(entityClass))
}
@@ -80,7 +80,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType {
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
*/
@objc
public convenience init(entityClass: AnyClass, configuration: String?) {
public convenience init(entityClass: NSManagedObject.Type, configuration: ModelConfiguration) {
self.init(Into(entityClass, configuration))
}
@@ -122,7 +122,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType {
// MARK: - Into
extension Into: CoreStoreSwiftType {
extension Into where T: NSManagedObject {
// MARK: CoreStoreSwiftType
@@ -130,4 +130,16 @@ extension Into: CoreStoreSwiftType {
return CSInto(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> Into<NSManagedObject> {
return Into<NSManagedObject>(
entityClass: self.entityClass,
configuration: self.configuration,
inferStoreIfPossible: self.inferStoreIfPossible
)
}
}

View File

@@ -46,7 +46,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT
- parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `CSLocalStorageOptionsNone`.
*/
@objc
public convenience init(fileURL: URL, configuration: String?, mappingModelBundles: [Bundle]?, localStorageOptions: Int) {
public convenience init(fileURL: URL, configuration: ModelConfiguration, mappingModelBundles: [Bundle]?, localStorageOptions: Int) {
self.init(
SQLiteStore(
@@ -68,7 +68,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT
- parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `[CSLocalStorageOptions none]`.
*/
@objc
public convenience init(fileName: String, configuration: String?, mappingModelBundles: [Bundle]?, localStorageOptions: Int) {
public convenience init(fileName: String, configuration: ModelConfiguration, mappingModelBundles: [Bundle]?, localStorageOptions: Int) {
self.init(
SQLiteStore(
@@ -133,7 +133,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT
/**
The configuration name in the model file
*/
public var configuration: String? {
public var configuration: ModelConfiguration {
return self.bridgeToSwift.configuration
}

View File

@@ -47,7 +47,7 @@ public protocol CSStorageInterface {
The configuration name in the model file
*/
@objc
var configuration: String? { get }
var configuration: ModelConfiguration { get }
/**
The options dictionary for the `NSPersistentStore`

View File

@@ -88,7 +88,7 @@ fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: CS
let controller = CoreStoreFetchedResultsController(
context: context,
fetchRequest: CoreStoreFetchRequest().dynamicCast(),
from: from?.bridgeToSwift.downcast(),
from: from?.bridgeToSwift,
sectionBy: sectionBy?.bridgeToSwift,
applyFetchClauses: { (fetchRequest) in