Core Data uniqueness

纵饮孤独 提交于 2019-12-11 13:14:38

问题


Is there any way I can validate a value updated in a Core Data entity's property against values of the property in other entities in the collection?

At the moment I create an entity with some default values, add it to arrangedObjects, then get the user to modify the various property values. However, I would like to check a particular property and make sure there're no other entities in the array with the same value for that property. What's the best way to do this?

Many thanks, Dany.


回答1:


Manually checking is only a few lines of code with a fast enumeration loop:

BOOL unique = YES;
for (NSManagedObject *obj in collection) {
    if (obj.property == value) {
        unique = NO;
        break;
    }
}


来源:https://stackoverflow.com/questions/2415537/core-data-uniqueness

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!