Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top