This commit is contained in:
John Estropia
2026-07-24 11:51:36 +09:00
parent 1ea9ad7c4a
commit 13093d72d4
51 changed files with 1083 additions and 243 deletions
+45 -1
View File
@@ -121,7 +121,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter persistentID: the `DynamicObjectID` pertaining ot the `NSManagedObject` or `CoreStoreObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/
public func edit<O: DynamicObject>(
public func edit<O>(
_ persistentID: DynamicObjectID<O>?
) -> O? {
@@ -157,6 +157,30 @@ public /*abstract*/ class BaseDataTransaction {
return self.context.fetchExisting(object)
}
/**
Returns an editable proxy of the object with the specified `DynamicObjectID`.
- parameter into: an `Into` clause specifying the entity type
- parameter persistentID: the `DynamicObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/
public func edit<O>(
_ into: Into<O>,
_ persistentID: DynamicObjectID<O>
) -> O? {
Internals.assert(
self.isRunningInAllowedQueue(),
"Attempted to update an entity of type \(Internals.typeName(into.entityClass)) outside its designated queue."
)
Internals.assert(
into.inferStoreIfPossible
|| (into.configuration ?? DataStack.defaultConfigurationName) == persistentID.managedObjectID.persistentStore?.configurationName,
"Attempted to update an entity of type \(Internals.typeName(into.entityClass)) but the specified persistent store do not match the `NSManagedObjectID`."
)
return self.fetchExisting(persistentID)
}
/**
Returns an editable proxy of the object with the specified `NSManagedObjectID`.
@@ -180,6 +204,26 @@ public /*abstract*/ class BaseDataTransaction {
)
return self.fetchExisting(objectID)
}
/**
Deletes the objects with the specified `DynamicObjectID`s.
- parameter persistentIDs: the `DynamicObjectID`s of the objects to delete
*/
public func delete<O: DynamicObject, S: Sequence>(
persistentIDs: S
) where S.Iterator.Element == DynamicObjectID<O> {
Internals.assert(
self.isRunningInAllowedQueue(),
"Attempted to delete an entity outside its designated queue."
)
let context = self.context
persistentIDs.forEach {
context.fetchExisting($0).map({ context.delete($0.cs_toRaw()) })
}
}
/**
Deletes the objects with the specified `NSManagedObjectID`s.