I have a NSOutlineView that shows data from my Core Data store. The data is presented using an NSarrayController linked to my managedObjectContext and displayed in the NSOutlineView using NSTreeController (much like described here). I would like to filter what data are shown using NSPredicate (or something else) but I can't get this to work. Note that this is OSX and not iOS so I can't use NSFetchedResultsController.
I am able to retrieve the correct data and store these in a NSArray. However, enabling an automatic update of what I see in my outlineview using only the filtered data does not work. This is what I currently have:
[arrayController setManagedObjectContext:_coreDataHelper.context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SDRDFileObject"
inManagedObjectContext:_coreDataHelper.context];
[request setEntity:entity];
NSNumber *directionLimit = @1;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"direction = %@", directionLimit];
[request setPredicate:predicate];
NSError *error;
[arrayController setContent:[_coreDataHelper.context executeFetchRequest:request error:&error]];
[_coreDataHelper.context reset];
[arrayController fetch:self];
[outlineView reloadData];
As you can see my question is close to this one, but I am still struggling. If I do get this to work using setContent for the arrayController I also assume that I will run into trouble with having mismatch between the Core Data context and the content of the arrayController. Suggestions or an example for how to correctly do this is greatly appreciated.