NSSortDescriptor has the method sortDescriptorWithKey:ascending:selector:
.
This takes the object being sorted, finds object's the Key-Value Coding property for key
, then sends that property the stated selector.
I would instead like to send the object itself the selector, to directly sort the object by one of it's methods.
I have tried key @"self"
, which fails with the following error:
[NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES selector:@selector(compare:)];
'NSInvalidArgumentException', reason: 'keypath #self not found in entity
Is there any way to sort using one of the object's methods, rather than one of the property's?
(BTW, I can't use sortDescriptorWithKey:ascending:comparator:
due to Core Data. This will also be used with an NSFetchedResultsController
and delegate.)
EDIT:
Full code for what I'd like to do, with Core Data + NSFetchRequest:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"MYClass" inManagedObjectContext:ManagedObjectContext]];
[request setFetchBatchSize:20];
// This is where I am having the problem. Self?
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES selector:@selector(compare:)];
[request setSortDescriptors:@[sortDescriptor]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hidden != %@", @YES];
[request setPredicate:predicate];
NSFetchedResultsController *newController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:[[ATBackend sharedBackend] managedObjectContext] sectionNameKeyPath:@"sectionKeyPath" cacheName:@"myCache"];
newController.delegate = self;
_fetchedMessagesController = newController;