Core Data的唯一属性 [英] Core Data unique attributes

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

问题描述

是否可以使Core Data属性唯一,即没有两个MyEntity对象可以具有相同的myAttribute?

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

我知道如何强制执行这个程序,我希望有一种方法可以使用xcode中的图形化数据模型编辑器。

I know how to enforce this programatically, but I'm hoping there's a way to do it using the graphical Data Model editor in xcode.

我使用的是iPhone 3.1.2 SDK。

I'm using the iPhone 3.1.2 SDK.

推荐答案

我决定使用 validate< key>:error:已经有一个具有特定值< key> 的Managed Object。

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.

例如:

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

感谢Martin Cote对他的投入。

Thanks to Martin Cote for his input.

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

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