Core Data unique attributes

后端 未结 7 1354
眼角桃花
眼角桃花 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:error: method to check if there is already a Managed Object with the specific value of . 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.

提交回复
热议问题