不支持的NSSortDescriptor(不支持比较器块) [英] unsupported NSSortDescriptor (comparator blocks are not supported)

查看:160
本文介绍了不支持的NSSortDescriptor(不支持比较器块)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fetchedResultsController 中设置 NSSortDescriptor iam收到此错误不支持的NSSortDescriptor(不支持比较器块) )即可。

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];

                          }];


推荐答案

你不能在任何地方使用带有比较器块的排序描述符 - 例如没有Core Data提取。

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?

这篇关于不支持的NSSortDescriptor(不支持比较器块)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆