开发者

How to (properly) create unique object IDs for instances of NSManagedObject?

I want to set custom NSManagedObject IDs to match the IDs of their corresponding objects in my CouchDB. The CoreData documentation (in "Using Managed Objects") says:

You can sometimes benefit from creating your own unique ID (UUID) property which can be defined a开发者_开发百科nd set for newly inserted objects. This allows you to efficiently locate specific objects using predicates (though before a save operation new objects can be found only in their original context).

But the NSManagedObjectContext documentation says you "absolutely must not override" objectID.

So, how does one properly set a custom object ID?


Reading through the documentation I think it is suggesting that you create an additional property on your object that stores your own UUID (the ID from CouchDB in this case) rather than overriding objectID. You can then use a predicate to search against your own UUID property you created and stored the CouchDB ID in. Note that you must perform a save operation first if you are searching outside of the original context.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜