mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-26 03:11:30 +01:00
force dynamic dispatch on generic types
This commit is contained in:
@@ -99,7 +99,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
"Attempted to create an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
"Attempted to create an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))."
|
||||||
)
|
)
|
||||||
|
|
||||||
return super.create(into)
|
return super.create(into)
|
||||||
@@ -132,7 +132,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
"Attempted to update an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
"Attempted to update an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))."
|
||||||
)
|
)
|
||||||
|
|
||||||
return super.edit(into, objectID)
|
return super.edit(into, objectID)
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
*/
|
*/
|
||||||
public func create<T: NSManagedObject>(_ into: Into<T>) -> T {
|
public func create<T: NSManagedObject>(_ into: Into<T>) -> T {
|
||||||
|
|
||||||
|
let entityClass = (into.entityClass as! T.Type)
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to create an entity of type \(cs_typeName(T.self)) outside its designated queue."
|
"Attempted to create an entity of type \(cs_typeName(entityClass)) outside its designated queue."
|
||||||
)
|
)
|
||||||
|
|
||||||
let context = self.context
|
let context = self.context
|
||||||
let entityClass = (into.entityClass as! NSManagedObject.Type)
|
|
||||||
if into.inferStoreIfPossible {
|
if into.inferStoreIfPossible {
|
||||||
|
|
||||||
switch context.parentStack!.persistentStoreForEntityClass(
|
switch context.parentStack!.persistentStoreForEntityClass(
|
||||||
@@ -68,7 +68,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
case (let persistentStore?, _):
|
case (let persistentStore?, _):
|
||||||
let object = entityClass.createInContext(context) as! T
|
let object = entityClass.createInContext(context)
|
||||||
context.assign(object, to: persistentStore)
|
context.assign(object, to: persistentStore)
|
||||||
return object
|
return object
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
case (let persistentStore?, _):
|
case (let persistentStore?, _):
|
||||||
let object = entityClass.createInContext(context) as! T
|
let object = entityClass.createInContext(context)
|
||||||
context.assign(object, to: persistentStore)
|
context.assign(object, to: persistentStore)
|
||||||
return object
|
return object
|
||||||
|
|
||||||
@@ -139,12 +139,12 @@ public /*abstract*/ class BaseDataTransaction {
|
|||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
"Attempted to update an entity of type \(cs_typeName(T.self)) outside its designated queue."
|
"Attempted to update an entity of type \(cs_typeName(into.entityClass)) outside its designated queue."
|
||||||
)
|
)
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
into.inferStoreIfPossible
|
into.inferStoreIfPossible
|
||||||
|| (into.configuration ?? Into.defaultConfigurationName) == objectID.persistentStore?.configurationName,
|
|| (into.configuration ?? Into.defaultConfigurationName) == objectID.persistentStore?.configurationName,
|
||||||
"Attempted to update an entity of type \(cs_typeName(T.self)) but the specified persistent store do not match the `NSManagedObjectID`."
|
"Attempted to update an entity of type \(cs_typeName(into.entityClass)) but the specified persistent store do not match the `NSManagedObjectID`."
|
||||||
)
|
)
|
||||||
return self.fetchExisting(objectID) as? T
|
return self.fetchExisting(objectID) as? T
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
"Attempted to create an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
"Attempted to create an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))."
|
||||||
)
|
)
|
||||||
|
|
||||||
return super.create(into)
|
return super.create(into)
|
||||||
@@ -127,7 +127,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
|||||||
|
|
||||||
CoreStore.assert(
|
CoreStore.assert(
|
||||||
!self.isCommitted,
|
!self.isCommitted,
|
||||||
"Attempted to update an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
"Attempted to update an entity of type \(cs_typeName(into.entityClass)) from an already committed \(cs_typeName(self))."
|
||||||
)
|
)
|
||||||
|
|
||||||
return super.edit(into, objectID)
|
return super.edit(into, objectID)
|
||||||
|
|||||||
Reference in New Issue
Block a user