如何在iPhone核心数据中为实体创建唯一标识符 [英] How to create unique identifier for an entity in iphone core data

查看:62
本文介绍了如何在iPhone核心数据中为实体创建唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是核心数据和iPhone编程的新手,所以不要介意我愚蠢的qn。
我不知道如何在xcdatamodel文件中将属性标记为主键,或者可能在外部。我环顾四周,发现有人说这是不可能的。

I am new to core data and iphone programming so dont mind my silly qn. I couldn't figure out how to mark a attribute as a primary key in the xcdatamodel file or may be outside. I looked around and found some people saying that it is not possible.

我正在获取要获取的每个对象的标识符,我需要通过核心存储该对象数据,我可能需要在我的Web服务中使用该标识符来检索其他数据。
如何保持实体的主键等于该标识符,我们将不胜感激。

I am getting identifier for every object that i am getting, i would need to store that object through core data and i might need to use that identifier in my web service to retrieve additional data. How do i keep the primary key of an entity equal to that identifier, any help is greatly appreciated.

请先感谢

Yogesh

推荐答案

简而言之,您不能将属性自动标记为主键。您可以自己维护一个。

In short you cannot mark an attribute as primary key automatically. You have maintain one by your own.

您可以执行以下任一操作:

You can do anyone of the below:

使用 [NSManagedObject objectID]

您自己的类似于主键的系统,该系统将整数存储在模型中,并随着创建而增加每个对象的数量

Your own primary key-like system that stores an integer in your model and increments it with the creation of each object

这篇关于如何在iPhone核心数据中为实体创建唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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