質問

How does one retrieve the NSManagedObjectID when saving an object to Core-Data?

I have a series of objects to save to Core-Data and I need to have each ones objectID as I am saving on another thread.

I would then like to pass this array to the main thread and fetch the objects for the array of IDs.

役に立ちましたか?

解決

You can use key value coding which is very convenient:

NSArray *objects; // the objects you are saving
NSArray *objectIDs = [objects valueForKeyPath:@"objectID"];

However, this does not make too much sense. Why don't you just pass the array of objects right away? You could also retrieve them from the store with a suitable predicate.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top