Array of NSManagedObjectID, fetching objects immediately

I have an array of NSManagedObjectID. Is there a more efficient way to get related managed objects, rather than looping through an array and getting them individually?

+5
source share
1 answer

Run a fetchRequestwith 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;
+6
source

All Articles