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.

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top