I have an array of NSManagedObjectID. Is there a more efficient way to fetch the associated managed objects either than looping through the array and getting them individually?
Perform a fetchRequest
with the following predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self in %@", arrayOfIds];
Full example
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = myEntityDescription;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self in %@", arrayOfIds];
fetchRequest.predicate = predicate;
fetchRequest.sortDescriptors = mySortDescriptors;
NSError *error = nil;
NSArray *managedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
[fetchRequest release]; fetchRequest = nil;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With