Using a NSFetchedResultsController with an NSManagedObject and fetched properties

淺唱寂寞╮ 提交于 2019-12-11 02:45:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!