From a263851266a2640a0033c5590fb62388d25bd710 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Mon, 17 Aug 2015 23:50:03 +0900 Subject: [PATCH] import array of ImportableObjects --- .../BaseDataTransaction+Importing.swift | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift index c8e7326..e5d2b93 100644 --- a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift +++ b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift @@ -83,6 +83,55 @@ public extension BaseDataTransaction { } } + func importObjects( + into: Into, + 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( + into: Into, + 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( into: Into, source: T.ImportSource) throws -> T? {