为 iPhone 上的 Core Data 程序创建唯一 ID [英] Creating a unique id for a Core Data program on the iPhone
问题描述
我在弄清楚这个 Core Data 内容时遇到了一些麻烦.如何创建具有唯一 ID 的新条目?在 SQL 中,我只会将一个字段声明为自动增量字段.我在这里没有看到类似的东西,但我可能只是遗漏了一些东西.我只想要一个自动递增的 NSInteger 字段,所以当我手动将项目添加到数据库时,我会有某种形式的引用它们.
I am having a bit of trouble figuring out this Core Data stuff. How do I create a new entry with a unique ID? In SQL I would just declare one field as an autoincrement field. I'm not seeing anything like that here, but I could just be missing something. I just want an auto incrementing NSInteger field, so when I manually add items to the database, I will have some form of reference to them.
推荐答案
虽然我同意你说的,但核心数据背后有一个 ID 机制.ID 确实由 Core-Data 管理,但您可以使用以下命令检索它们:
Though i agree with what you said, there is an ID mechanism behind core data. ID are indeed managed by Core-Data but you can retrieve them with :
NSManagedObjectID *moID = [managedObject objectID];
有关更多信息,请参阅:核心数据编程指南
For more informations see : Core Data Programming Guide
这篇关于为 iPhone 上的 Core Data 程序创建唯一 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!