核心数据唯一性 [英] Core Data uniqueness

查看:89
本文介绍了核心数据唯一性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么方法可以验证核心数据实体的属性中更新的值与集合中其他实体的属性值?

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?

创建具有一些默认值的实体,将它添加到 arrangedObjects ,然后让用户修改各种属性值。但是,我想检查一个特定的属性,并确保数组中没有其他实体具有相同的属性值。这是最好的方法是什么?

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?

非常感谢,
Dany。

Many thanks, Dany.

推荐答案

手动检查只有几行具有快速枚举循环的代码:

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;
    }
}

这篇关于核心数据唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆