utility to update an existing ImportableObject from its ImportSource (fixes #52)

This commit is contained in:
John Rommel Estropia
2016-02-20 12:26:23 +09:00
parent 1af675e8b7
commit 6c95b010e9

View File

@@ -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<T where T: NSManagedObject, T: ImportableObject>(
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.