I don't know if this question is specific to MagicalRecord or if it is a CoreData question.
What I am trying to archive is to represent a folder-structure with subfolders and files.
If love to have an NSFetchedResultsController with two sections.
I can make two seperate NSFetchedResultsController by doing something like this:
NSFetchedResultsController* subFolderFetchedResultsController = [Folder fetchAllSortedBy:@"folderName" ascending:YES withPredicate:[NSPredicate predicateWithFormat:@"parent == %@", folder] groupBy:nil delegate:self];
NSFetchedResultsController* filesFetchedResultsController = [File fetchAllSortedBy:@"folderName" ascending:YES withPredicate:[NSPredicate predicateWithFormat:@"folder == %@", folder] groupBy:nil delegate:self];
but i'd prefer to have just one NSFetchedResultsController.
Is there any solution on how i can make this working?
Ok, I already found the solution for my problem. I made a superclass for my NSManagedObjects, and make the Request like [SuperClass fetchAllSortedBy:.......]
But... I now have a new problem ;)
I have this one super class and in a TableViewController I would like to display online Items of a certain kind. So I want to display items of ClassA and ClassB but not ClassC. All of those classes inherit from this one superclass. Is there a possibility to tell the fetch with for example an NSPredicate that it should only care about results that are of ClassA and B?
I hope you do understand my problem?!?
I guess it's similar to this problem here: http://stackoverflow.com/questions/2554894/is-it-possible-to-filter-an-nsarray-by-class
[NSPredicate predicateWithFormat:@"self isKindOfClass: %@",[ClassA class]];
is not working with MR.
Any help is appreciated!
Hi @georgbachman — I assume you’ve long since resolved this problem, but for posterity’s sake, the best way I can think of is to embed the entity name into the model for just these types of objects. You’d need to be ready to migrate the data if you ever renamed an entity, but you could do it reasonably automatically using an abstract parent entity, with child entities that specify their type with a default value set to their entity name.
You’re not alone in wanting this.
Be sure to post back here if you found a better way to handle this in the time that’s passed!