Prevent duplicates when importing RSS feed to Core Data

后端 未结 2 1734
鱼传尺愫
鱼传尺愫 2021-01-03 08:43

Trying to import a RSS feed into Core Data. Once they are imported, when trying to update the feed again afterwards, how do I most efficiently prevent duplicates. Right now

2条回答
  •  清酒与你
    2021-01-03 09:22

    When you are importing a new row you can run a query against the existing rows to see if it is already in place. To do this you create a NSFetchRequest against your entity, set the predicate to look for the guid property and set the max rows returned to 1.

    I would recommend keeping this NSFetchRequest around during your import so that you can reuse it while going through the import. If the NSFetchRequest returns a row you can update that row. If it does not return a row then you can insert a new row.

    When done correctly you will find the performance more than acceptable.

提交回复
热议问题