mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-22 17:39:52 +01:00
fix type method dispatch when importing objects
This commit is contained in:
@@ -50,7 +50,9 @@ public extension BaseDataTransaction {
|
|||||||
|
|
||||||
return try autoreleasepool {
|
return try autoreleasepool {
|
||||||
|
|
||||||
guard T.shouldInsert(from: source, in: self) else {
|
let entityType = into.entityClass as! T.Type
|
||||||
|
|
||||||
|
guard entityType.shouldInsert(from: source, in: self) else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -78,8 +80,10 @@ public extension BaseDataTransaction {
|
|||||||
)
|
)
|
||||||
|
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
guard T.shouldInsert(from: source, in: self) else {
|
let entityType = type(of: object)
|
||||||
|
|
||||||
|
guard entityType.shouldInsert(from: source, in: self) else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -108,8 +112,10 @@ public extension BaseDataTransaction {
|
|||||||
return try autoreleasepool {
|
return try autoreleasepool {
|
||||||
|
|
||||||
return try sourceArray.flatMap { (source) -> T? in
|
return try sourceArray.flatMap { (source) -> T? in
|
||||||
|
|
||||||
guard T.shouldInsert(from: source, in: self) else {
|
let entityType = into.entityClass as! T.Type
|
||||||
|
|
||||||
|
guard entityType.shouldInsert(from: source, in: self) else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -142,16 +148,18 @@ public extension BaseDataTransaction {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return try autoreleasepool {
|
return try autoreleasepool {
|
||||||
|
|
||||||
let uniqueIDKeyPath = T.uniqueIDKeyPath
|
let entityType = into.entityClass as! T.Type
|
||||||
guard let uniqueIDValue = try T.uniqueID(from: source, in: self) else {
|
|
||||||
|
let uniqueIDKeyPath = entityType.uniqueIDKeyPath
|
||||||
|
guard let uniqueIDValue = try entityType.uniqueID(from: source, in: self) else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if let object = self.fetchOne(From<T>(), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) {
|
if let object = self.fetchOne(From(entityType), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) {
|
||||||
|
|
||||||
guard T.shouldUpdate(from: source, in: self) else {
|
guard entityType.shouldUpdate(from: source, in: self) else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -161,7 +169,7 @@ public extension BaseDataTransaction {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
guard T.shouldInsert(from: source, in: self) else {
|
guard entityType.shouldInsert(from: source, in: self) else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -195,13 +203,15 @@ public extension BaseDataTransaction {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return try autoreleasepool {
|
return try autoreleasepool {
|
||||||
|
|
||||||
|
let entityType = into.entityClass as! T.Type
|
||||||
|
|
||||||
var mapping = Dictionary<T.UniqueIDType, T.ImportSource>()
|
var mapping = Dictionary<T.UniqueIDType, T.ImportSource>()
|
||||||
let sortedIDs = try autoreleasepool {
|
let sortedIDs = try autoreleasepool {
|
||||||
|
|
||||||
return try sourceArray.flatMap { (source) -> T.UniqueIDType? in
|
return try sourceArray.flatMap { (source) -> T.UniqueIDType? in
|
||||||
|
|
||||||
guard let uniqueIDValue = try T.uniqueID(from: source, in: self) else {
|
guard let uniqueIDValue = try entityType.uniqueID(from: source, in: self) else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -214,14 +224,14 @@ public extension BaseDataTransaction {
|
|||||||
mapping = try autoreleasepool { try preProcess(mapping) }
|
mapping = try autoreleasepool { try preProcess(mapping) }
|
||||||
|
|
||||||
var objects = Dictionary<T.UniqueIDType, T>()
|
var objects = Dictionary<T.UniqueIDType, T>()
|
||||||
for object in self.fetchAll(From<T>(), Where(T.uniqueIDKeyPath, isMemberOf: sortedIDs)) ?? [] {
|
for object in self.fetchAll(From(entityType), Where(entityType.uniqueIDKeyPath, isMemberOf: sortedIDs)) ?? [] {
|
||||||
|
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
let uniqueIDValue = object.uniqueIDValue
|
let uniqueIDValue = object.uniqueIDValue
|
||||||
|
|
||||||
guard let source = mapping.removeValue(forKey: uniqueIDValue),
|
guard let source = mapping.removeValue(forKey: uniqueIDValue),
|
||||||
T.shouldUpdate(from: source, in: self) else {
|
entityType.shouldUpdate(from: source, in: self) else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -235,7 +245,7 @@ public extension BaseDataTransaction {
|
|||||||
|
|
||||||
try autoreleasepool {
|
try autoreleasepool {
|
||||||
|
|
||||||
guard T.shouldInsert(from: source, in: self) else {
|
guard entityType.shouldInsert(from: source, in: self) else {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user