mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 10:21:40 +01:00
utility to update an existing ImportableObject from its ImportSource (fixes #52)
This commit is contained in:
@@ -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.
|
Creates multiple `ImportableObject`s by importing from the specified array of import sources.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user