From 6c95b010e97fb9ffa93201e6863b5fb00cd52713 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sat, 20 Feb 2016 12:26:23 +0900 Subject: [PATCH] utility to update an existing ImportableObject from its ImportSource (fixes #52) --- .../BaseDataTransaction+Importing.swift | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift index 6f470ad..3212ea7 100644 --- a/CoreStore/Importing Data/BaseDataTransaction+Importing.swift +++ b/CoreStore/Importing Data/BaseDataTransaction+Importing.swift @@ -60,6 +60,32 @@ public extension BaseDataTransaction { } } + /** + Updates an existing `ImportableObject` by importing values from the specified import source. + + - parameter object: the `NSManagedObject` to update + - parameter source: the object to import values from + */ + public func importObject( + object: T, + source: T.ImportSource) throws { + + CoreStore.assert( + self.isRunningInAllowedQueue(), + "Attempted to import an object of type \(typeName(object)) outside the transaction's designated queue." + ) + + try autoreleasepool { + + guard T.shouldInsertFromImportSource(source, inTransaction: self) else { + + return + } + + try object.didInsertFromImportSource(source, inTransaction: self) + } + } + /** Creates multiple `ImportableObject`s by importing from the specified array of import sources.