Creating a unique id for a Core Data program on the iPhone

前端 未结 9 1561
暖寄归人
暖寄归人 2020-12-04 07:28

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 fie

9条回答
  •  无人及你
    2020-12-04 07:46

    Core data is used for persistance framework, this framework abstracts the primary key.

    Each NSManagedObject has its own unique key built in which is available in its objectID property.

    This id is internally used to link entities over its relations. There is no need to maintain an own id as a primary key as you are used to do in SQL.

    You can always get the id by NSManagedObject.objectID. and fetching object context using NSMananagedObjectContext.objectWithId

提交回复
热议问题