Instead of modifying Tarek's code, my solution was to create a category on SCTableViewSection:
SCTableViewSection+predicate.h
#import <Foundation/Foundation.h>
#import "SCTableViewSection.h"
@interface SCTableViewSection (helper)
+ (id)sectionWithHeaderTitle:(NSString *)sectionHeaderTitle
withEntityClassDefinition:(SCClassDefinition *)classDefinition
usingPredicate:(NSPredicate*)predicate;
- (id)initWithHeaderTitle:(NSString *)sectionHeaderTitle withEntityClassDefinition:(SCClassDefinition *)classDefinition
usingPredicate:(NSPredicate*)predicate;
@end
SCTableViewSection+predicate.m
#import "SCTableViewSection+predicate.h"
@implementation SCTableViewSection (helper)
+ (id)sectionWithHeaderTitle:(NSString *)sectionHeaderTitle
withEntityClassDefinition:(SCClassDefinition *)classDefinition
usingPredicate:(NSPredicate*)predicate
{
return [[[[self class] alloc] initWithHeaderTitle:sectionHeaderTitle
withEntityClassDefinition:classDefinition
usingPredicate:predicate] autorelease];
}
- (id)initWithHeaderTitle:(NSString *)sectionHeaderTitle withEntityClassDefinition:(SCClassDefinition *)classDefinition
usingPredicate:(NSPredicate*)predicate
{
// Create the sectionItems array
NSMutableArray *sectionItems = nil;
if(classDefinition.entity)
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:classDefinition.entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:classDefinition.keyPropertyName
ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setPredicate:predicate];
sectionItems = [NSMutableArray arrayWithArray:[classDefinition.managedObjectContext
executeFetchRequest:fetchRequest
error:NULL]];
[sortDescriptor release];
[sortDescriptors release];
[fetchRequest release];
}
return [self initWithHeaderTitle:sectionHeaderTitle withItems:sectionItems
withClassDefinition:classDefinition];
}
@end
This way I don't have to alter the SCTableViewSection and can keep it current.
Just add #import SCTableViewSection+predicate.h to your view controller.