gpt4 book ai didi

core-data - NSManagedObject的objectID : is it consistent?

转载 作者:行者123 更新时间:2023-12-04 09:54:18 32 4
gpt4 key购买 nike

我需要使用一些唯一且一致的ID来索引数据,我尝试使用NSManagedObject的objectID,但是对于同一实体,它的objectID不断变化,有人知道这是否不一致吗?

最佳答案

除非您没有保存新对象,否则objectID是唯一且一致的。

引用Core Data Programming Guide:

Managed Object IDs and URIs

An NSManagedObjectID object is a universal identifier for a managed object, and provides basis for uniquing in the Core Data Framework. A managed object ID uniquely identifies the same managed object both between managed object contexts in a single application, and in multiple applications (as in distributed systems). Like the primary key in the database, an identifier contains the information needed to exactly describe an object in a persistent store, although the detailed information is not exposed. The framework completely encapsulates the “external” information and presents a clean object oriented interface.

NSManagedObjectID *moID = [managedObject objectID]; 

There are two forms of an object ID. When a managed object is first created, Core Data assigns it a temporary ID; only if it is saved to a persistent store does Core Data assign a managed object a permanent ID. You can readily discover whether an ID is temporary:

BOOL isTemporary = [[managedObject objectID] isTemporaryID];

关于core-data - NSManagedObject的objectID : is it consistent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10827107/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com