Using custom sections with NSFetchedResultsController?
cocoa-touch, core-data, iphone, uitableview
Solution
You can try the following.
Add a transient attribute to your core data model in the Task entity. Then implement the
- (void)awakeFromFetch
method in your Task NSManagedObject class. See its documentation. Within the method you are allowed to set a value for the transient property using the values of the other properties. Note that there are some restrictions on what you can do, but this is well explained in the documentation (most notably you can not modify relationships or pass arguments; however, if you can compute you transient property using only the values of the other properties/relationships it should be perfectly fine).
Once you have done this, you simply use the transient property as the attribute you pass to get back the sections.
Problem
I'm making a sectioned table with fetched results, but am having a hard time getting custom sections worked out. Normally one would just have an attribute to sort by, and use `sectionNameKeyPath:` to generate the sections. But my sorting attribute is calculated on the fly, and I can't seem to get the `fetchedResultsController` to use it correctly... Update: Using jbrennan's advice below, I'm really close to the intended functionality. I've added a Category to `NSDate` that returns a "days ago" number; putting that in here gives me sections based on those numbers: ``` NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"myDateAttribute.daysAgo" cacheName:@"Root"]; ``` Here's where I'm stuck: I don't need them sorted by "days ago," I need them sorted via some calculations based on other attributes in the entity. So I can't just call that custom Category method, I need to call a method with arguments, like so: ``` [myDateAttribute sortingRoutine:thisObject.value] ``` Or something like that. I hope that makes some degree of sense. Thanks a ton if you can help :)