unsupported NSSortDescriptor (comparator blocks are not supported)

ios, nsfetchedresultscontroller, nssortdescriptor

Solution

You can't use sort descriptors with comparator blocks everywhere - for instance not with Core Data fetches.

They work fine when you filter normal arrays, though.

Apart from that - was there a question in there that I overlooked?

Problem

In `fetchedResultsController` while setting the `NSSortDescriptor` iam getting this error unsupported NSSortDescriptor (comparator blocks are not supported). ``` NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Alarm" inManagedObjectContext: managedObjectContext]; [fetchRequest setEntity:entity]; //Below code is not working and causing error. sorting use the hours&seconds part of the time attribute NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"time" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components1 = [calendar components:(NSHourCalendarUnit|NSMinuteCalendarUnit) fromDate:obj1]; NSDateComponents *components2 = [calendar components:(NSHourCalendarUnit|NSMinuteCalendarUnit) fromDate:obj2]; NSDate *date1 = [calendar dateFromComponents:components1]; NSDate *date2 = [calendar dateFromComponents:components2]; return [date1 compare:date2]; }]; ```

Original source

Related problems