import array of ImportableObjects

This commit is contained in:
John Rommel Estropia
2015-08-17 23:50:03 +09:00
parent cbc3eb8887
commit a263851266

View File

@@ -83,6 +83,55 @@ public extension BaseDataTransaction {
}
}
func importObjects<T where T: NSManagedObject, T: ImportableObject>(
into: Into<T>,
sourceArray: [T.ImportSource]) throws {
CoreStore.assert(
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
)
try autoreleasepool {
for source in sourceArray {
try autoreleasepool {
let object = self.create(into)
try object.didInsertFromImportSource(source)
}
}
}
}
func importObjects<T where T: NSManagedObject, T: ImportableObject>(
into: Into<T>,
sourceArray: [T.ImportSource],
postProcess: (sorted: [T]) -> Void) throws {
CoreStore.assert(
self.bypassesQueueing || self.transactionQueue.isCurrentExecutionContext(),
"Attempted to import an object of type \(typeName(into.entityClass)) outside the transaction's designated queue."
)
try autoreleasepool {
var objects = [T]()
for source in sourceArray {
try autoreleasepool {
let object = self.create(into)
try object.didInsertFromImportSource(source)
objects.append(object)
}
}
postProcess(sorted: objects)
}
}
func importUniqueObject<T where T: NSManagedObject, T: ImportableUniqueObject>(
into: Into<T>,
source: T.ImportSource) throws -> T? {