问题
I have a database of Cards and Printings that I have in one store (reference data) and my user's data of Containers and CardInstances in another store (as Apple suggests). Each user's card is a table CardInstance that contains a specific printingID that corresponds with a specific printing of a card. I'm trying to use a NSFetchedResultsController to filter the values of the cards so that it can manage the groupings and stuff using reusable code.
Again, here's the basic overview of the tables:
Card (which has nameNormalized and alphaNormalized and typeNormalized properties that I want to filter and group on in the Fetched Results Controller).
Printing (which has a card relationship and a specific printingID)
CardInstance (which has a container relationship, a printingID property, and a printingFetch fetched property on Printing with predicate: printingID = $FETCH_SOURCE.printingID).
Container (which has a to-many relationship of CardInstances).
Given a Container, I'm wanting to use a NSFetchedResultsController so that I can change the sort and groupings between name and type sections. So I have a fetchRequest where I've set the entity type to CardInstance and one predicate to container = %@, the given container.
1) How do I set the sort descriptors so that I can sort on printingFetch.card.nameNormalized or on printingFetch.card.typeNormalized?
2) How do I filter the results if I want to find all cards containing the word @"the"? I was thinking something along the lines of printingFetch.card.nameNormalized contains %@, @"the", but that just results in a crash.
I realize I could do this all manually, but if the container ends up containing a lot of cards, that may be way too slow and I'd like to not have to re-write the sectioning and grouping code that NSFetchedResultsController should automatically do for me.
来源:https://stackoverflow.com/questions/16391255/using-a-nsfetchedresultscontroller-with-an-nsmanagedobject-and-fetched-propertie