我们可以在核心数据中定义自动增量属性吗? [英] Can we define auto increment attribute in core data?

查看:80
本文介绍了我们可以在核心数据中定义自动增量属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在我的应用程序中使用核心数据,并希望在每个实体中将ID属性设置为自动增量。核心数据是否可能?或者我必须手动插入条目并以编程方式管理增量?

Hello I am using core data in my application, and want to set ID attribute in every entity as autoincrement. Is it possible in core data? Or I have to manually insert the entry and manage the increment programatically??

推荐答案

如果您正在考虑主要的ID键然后核心数据为您处理。在每个对象上都有一个 objectID 属性,您可以访问它来查看它。从托管对象上下文创建对象时,核心数据会分配临时ID。从托管对象上下文提交更改时,核心数据会分配一个永久ID。我不认为手动尝试设置它是个好主意。

If you are thinking of the id for the primary keys then core data handles this for you. On each object there is an objectID property you can access to see it. When you create an object from the managed object context, core data assigns a temporary id. When you commit the changes from the managed object context, core data assigns a perminant id. I don't think it would be a good idea to manually try and set this.

阅读此stackoverflow线程了解更多详情。

这篇关于我们可以在核心数据中定义自动增量属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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