Ok, I initially wanted to make NSSortDescriptor
of a request for NSFetchedResultsController
to sort based on the property in my NSManagedObject
subclass, but It obviously won't do it, because NSFetchedResultsController is limited to predicates and sort descriptors that work on the fetched entity and its relations, so I decided to create a transient attribute in my data model, synthesis the property for this attribute to ivar in my NSManagedObject
subclass, and sort based on it.
When running it, i got while executing fetch 'NSInvalidArgumentException', reason: 'keypath isActive not found in entity <NSSQLEntity SMSourceEntity id=2>'
I know this is KVO issue, so I have added + (NSSet*)keyPathsForValuesAffectingIsActive
, but still have the same issue.
What did I do wrong, or I'm still missing something to make it find my keypath? Thanks.
code:
@implementation SMSourceEntity
@dynamic friendlyName;
@dynamic interfaceAddress;
@dynamic uniqueID;
@dynamic network;
@synthesize isActive = _isActive;
+ (NSSet*)keyPathsForValuesAffectingIsActive
{
return [NSSet setWithObject:@"isActive"];
}
@end
my sortDescriptor:
request.sortDescriptors = [NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"isActive" ascending:NO] , nil];