在iPhone上为Core Data程序创建唯一的ID [英] Creating a unique id for a Core Data program on the iPhone
问题描述
我有一点麻烦找出这个核心数据的东西。如何创建具有唯一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屋!