numeric sort with NSSortDescriptor for NSFetchedResultsController
Posted
by
edziubudzik
on Stack Overflow
See other posts from Stack Overflow
or by edziubudzik
Published on 2011-01-14T12:08:23Z
Indexed on
2011/01/14
12:53 UTC
Read the original article
Hit count: 202
I'm trying to numerically sort data that's displayed in a UITableView.
Before that I used such a sort descriptor:
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
now I'd like to use block to sort this numerically like this:
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
return [((NSString *)obj1) compare:(NSString *)obj2 options:NSCaseInsensitiveSearch | NSNumericSearch];
}];
but it sorts the data incorectly causing conflict with section names in NSFetchedResultsController. So I tryed to immitate the old sorting with a comparator block - just to be sure that the problem is not caused by numeric comparison. The problem is that those lines:
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
return [((NSString *)obj1) caseInsensitiveCompare:(NSString *)obj2];
}];
also cause the same error and I don't see why they won't sort the data in the same way the first method did...
Any ideas?
© Stack Overflow or respective owner