Using a NSFetchedResultsController with an NSManagedObject and fetched properties
Asked Answered
E

0

2

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.

Eighty answered 6/5, 2013 at 2:36 Comment(2)
Why are these entities reside in different stores? apple specifically mentioned that it is not possible to create relationships across stores (only maintain them manually).Simpatico
Because the cards and printings are cached/generated reference data and the card instances and collections are user data. Apple specifically says to do this and not keep recreatable data in the user store.Eighty

© 2022 - 2024 — McMap. All rights reserved.