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

前端 未结 5 1358
温柔的废话
温柔的废话 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条回答
  •  猫巷女王i
    2021-02-03 14:57

    no, coredata has no built-in in uniquing as it isn't a DB.


    you have to assure uniqueness in your program logic.

    e.g. often, one does a fetch for an entry that should be unique and if that fetch has 1 entry, don't add another, else add it!

    ==> this works well for serial CD access, but can get complicated with multiple contexts that run in a multithreaded env

提交回复
热议问题