Is there any way we can restrict duplicate entries in core data?

前端 未结 5 1357
温柔的废话
温柔的废话 2021-02-03 14:30

I have been trying to add objects in core data. So, i want that it should not allow duplicate entries in core data store. How to do that? This is my code related to save data.

5条回答
  •  面向向阳花
    2021-02-03 14:58

    In Core Data there is no such thing as duplicate entries, as least as far as Core Data is concerned. Not in the sense of looking at it from a database point of view. Which makes sense because Core Data is not a database it is an object graph management system.

    So to prevent duplicates you need to do a search first then if the search returns NULL only then save, else do nothing.

    This article gives you code which you can customise to your needs

提交回复
热议问题