iOS - 核心数据集属性主键 [英] iOS - Core Data set attribute primary key
问题描述
我正在 Swift 中开发一个应用程序,最近开始使用 Core Data.我必须定义我的实体的哪个属性将是我的主键.例如:
我有一个具有类属性的实体:
- id
- 姓名
- 年龄
我需要id"属性是我的主键.
可能在Objective-C中也一样,只需要知道如何定义即可.
每个 NSManagedObject
都有自己唯一的内置密钥,可在其 objectID
属性中使用.>
此 ID 在内部用于通过其关系链接实体.不需要像在 SQL 中那样维护自己的 id 作为主键.
您始终可以通过 NSManagedObject.objectID
获取 id.
可以通过使用 NSMananagedObjectContext.objectWithId(...)
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:
- id
- name
- age
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 - 核心数据集属性主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!