核心数据对象唯一ID [英] core data object unique ID
问题描述
我想为我的托管对象实体模型添加一个唯一的ID字段。
我知道Core Data不使用ID关系, 。我需要一种方法来传递线程安全的数据到不同的线程,这样新的线程然后可以从该数据获取管理对象。
它可以是任何格式,但最好只有一个对象/变量/值。
我可以添加一个CFUUID作为NSString对象,但我不知道这是否理想?我应该做其他的事吗?
欢迎任何选择,或者只是确认CFUUID是要走的路。
as @Carl Veazey提到它:
NSManagedObjectID
正是你正在搜索的! p>
这里是一个简短的代码片段:
NSManagedObject * objectInMainContext = .. ..;
NSManagedObjectID * objectID = objectInMainContext.objectID;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^ {
NSManagedObjectContext * newThreadContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:...];
[newThreadContext objectWithID:objectID];
....
....
});
I'd like to add a unique ID field to my managed object entity model.
I know that Core Data doesn't use ID relationships but this is different. I need a way of passing thread safe data to a different thread so that the new thread can then fetch the managed object from that data.
It can be in any format but ideally just a single object/variable/value.
I could add a CFUUID to the object as an NSString but I'm not sure if this is ideal? Should I be doing something else?
Any alternatives are welcome, or even just confirmation that CFUUID is the way to go.
as @Carl Veazey mention it:
The NSManagedObjectID
is exactly what are you searching for!
and here ist a short snippet:
NSManagedObject *objectInMainContext = ....;
NSManagedObjectID *objectID = objectInMainContext.objectID;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSManagedObjectContext *newThreadContext = [[NSManagedObjectContext alloc] initWithConcurrencyType: ... ];
[newThreadContext objectWithID: objectID];
....
....
});
这篇关于核心数据对象唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!