Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData - Is there a good way to upsert items?

Just wondering whether there is a good way to upsert items in a CoreData db?

Or is there a way for me to consider a CoreData db as a set?

I mean, if I insert an item into the db and if there is already an identical redundant item there, the db ignores it. Any way to conveniently do it? or I have to query each time when I insert in order to avoid redundancy?

like image 760
Jackson Tale Avatar asked Sep 11 '12 16:09

Jackson Tale


1 Answers

I recently read this article

https://www.upbeat.it/upsert-in-core-data/

Basically, first create a constraint on the name, then you specify the TrumpMergePolicy in the Core Data context.

managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
like image 148
Amadeu Cavalcante Filho Avatar answered Sep 18 '22 18:09

Amadeu Cavalcante Filho