by Cesare Rocchi

Upsert in Core Data

I am a huge fan of upsert. An upsert operation creates a new record in a database, but if the record already exists it just updates it. All of that in the same query. Without upsert you’d need something like this (in pseudocode): if (record.exists?) { // update code here } else { // insert code here } The disadvantage of this is that you have to perform two queries, one to check the existence of the record and one either to update or to insert it.

Continue reading →

Pages(1)