Core Data: IN with ordered set of keys?
Core Data: IN with ordered set of keys?
- Subject: Core Data: IN with ordered set of keys?
- From: Dan Treiman <email@hidden>
- Date: Wed, 17 Apr 2013 16:41:00 -0500
I have a situation where I want to fetch an ordered array of managed objects which contain an ordered set of keys, and return the result in the same order as the input set:
NSOrderedSet * orderedIDs = ...;
NSFetchRequest * fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"MyEntityName"];
NSPredicate * predicate = [NSPredicate predicateWithFormat: @"uuid IN %@", orderedIDs];
NSArray * orderedObjects = [self.database.managedObjectContext executeFetchRequest:fetchRequest error:error];
By 'in the same order', I mean that I would like [[orderedIDs objectAtIndex:i] isEqual:[[orderedObjects objectAtIndex:i] uuid]] == YES for all valid indexes i. I implemented a solution that orders the result after the fetch by iterating through orderedIDs and building a new array, but I feel like there should be a more elegant answer. Any ideas?
Thanks!
- Dan Treiman
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden