iOS - Core Data集属性主键 [英] iOS - Core Data set attribute primary key
问题描述
我在Swift开发一个应用程序,最近开始使用Core Data。
我必须定义我的实体的哪个属性将是我的主键。例如:
我有一个具有类属性的实体:
- id
- id
- name
- age
我需要id属性是我的主键。
在Objective-C中可能是一样的,只需要知道如何定义它。
每个 NSManagedObject
都有自己的唯一键, $ c> objectID 属性。
此ID在内部用于链接实体的关系。
你总是可以通过获取id。 NSManagedObject.objectID
。
使用 NSMananagedObjectContext.objectWithId(...)$ c $可直接通过受管对象上下文执行通过其对象获取对象c>
I am developing an application in Swift and started using Core Data recently. I must define which attribute to my entity will be my primary key. For example:
I have an entity that has the attributes of the class:
I need the "id" attribute is my primary key.
May be the same in Objective-C, just need to know how to define it.
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
.
Fetching an object by its id can be performed directly by the managed object context using NSMananagedObjectContext.objectWithId(...)
这篇关于iOS - Core Data集属性主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!