Partial core data updates in Swift

Maybe I misunderstood the the 2019 WWDC video 'Making apps with core data'. Because when I use NSBatchInsertRequest together with NSMergeByPropertyObjectTrumpMergePolicy and unique constraints I can only add new records with the given id. Existing core data objects will not be partially updated.

Example Entity: Person

Attributes:

  • FirstName = John
  • LastName = Appleseed
  • ID = 1234 (unique constraint)

Goal in this example should be to change only the FirstName.

As far as I understood the session video we can omit some attributes and call NSBatchInsertRequest with the above ID and change FirstName to 'Johnny'. But this seems not to work. Maybe someone has an idea if I am doing something wrong here or if this is really not possible to omit values and change single attribute values.

I want to avoid fetching existing records, updating the values that should be changed and committing the changes back to the persistent store if there is maybe a better solution.

Partial core data updates in Swift
 
 
Q