Don't dump them into an array. Use a NSFetchedResultsController
. You will then be able to write many one-liners.
Anyway, the code logic is the same. Supposed you have all objects fetched in fetchedObjects
, you can do this:
NSArray *filtered = [fetchedObjects filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"otherEntity.attribute = %@", value]];
You could shorten this with a category on your managed object subclass and make it as simple as:
[myObject otherEntitiesWithAttribute:value];