I am trying to cast NSBatchInsertResult.result to the other types indicated in the enum (.objectIDs, and .count) and have not been successful.
I have implemented batch inserts of CoreData entities, and all is working using the WWDC 2019 Earthquakes app as a template.
I have multiple entities, and if there are no insertions or updates, I will not have to run through the "to-one" or "to-many" relationships after the batch insert.
I modified the Earthquakes example for my entities like this:
try await taskContext.perform {
let batchInsertRequest = self.festivalBatchInsertRequest(with: propertiesList)
if let fetchResult = try? taskContext.execute(batchInsertRequest),
let batchInsertResult = fetchResult as? NSBatchInsertResult,
let success = batchInsertResult.result as? Bool, success {
return
}
self.logger.debug("Failed to execute batch festival insert.")
throw IOError.batchInsertError
}
Currently, success is cast as Bool, and is properly reporting for successful or failed batch inserts.
The Apple Documentation also indicates that NSBatchInsertResult has members .result and .resultType and the desired result should be cast (as the documentation shows below):
"Cast the result to the type corresponding to resultType to inspect it. The following example shows how to inspect a result type of NSBatchInsertRequestResultType.statusOnly.
let success = batchInsertResult.result as? Bool
"
I am trying to cast .result to the other types indicated in the enum (.objectIDs, and .count) and have not been successful.
Any help on being able to examine the results of the batch insert more closely would be greatly appreciated!
Selecting any option will automatically load the page