Core Data unique attributes

后端 未结 7 1345
眼角桃花
眼角桃花 2020-12-02 10:01

Is it possible to make a Core Data attribute unique, i.e. no two MyEntity objects can have the same myAttribute?

I know how to enforce this programatically, but I\'m

相关标签:
7条回答
  • 2020-12-02 10:45

    I've decided to use the validate<key>:error: method to check if there is already a Managed Object with the specific value of <key>. An error is raised if this is the case.

    For example:

    - (BOOL)validateMyAttribute:(id *)value error:(NSError **)error {
        // Return NO if there is already an object with a myAtribute of value
    }

    Thanks to Martin Cote for his input.

    0 讨论(0)
提交回复
热议问题