Suppose a table named testTable:
(NSNumber*) numValue
(NSString*) stringValue
Then suppose about 50 records in it. numValue different in every record.
If I create NSFetchedResultController like this:
NSFetchRequest *request = [[NSFetchedResultsController alloc]
initWithFetchRequest: request
managedObjectContext: context
sectionNameKeyPath: @"numValue"
cacheName: @"testTable"]];
I'll get 50 sections then.
My question is:
How can I get 2 sections:
First containing records with numValue less than some x and second with records where numValue bigger than the same x.
For x = 15 it could look like this:
NSFetchRequest *request = [[NSFetchedResultsController alloc]
initWithFetchRequest: request
managedObjectContext: context
sectionNameKeyPath: @"numValue > 15"
cacheName: @"testTable"]];
Possible solutions are:
- We can edit our Entity as @Dima said.
- In the
numberOfSectionsInTableView:we can just look at the section names and compare them tox. Then we could look at these names intableView:numberOfRowsInSection:and calculate what we need to. But that's feels dirty too. Better than first approach, but still.
UPDATE: Well, I've almost figured out 3rd way to do that. Thanks to the @Dima's link. Here is the code:
[self setFetchedResultsController: [[NSFetchedResultsController alloc]
initWithFetchRequest: request
managedObjectContext: context
sectionNameKeyPath: [NSString stringWithFormat: @"numValue.compare(%f)", x]];
But there is a problem with KVC compliance: methods(selectors) with arguments aren't KVC compliant obviously. Any idea for workaround?