在索引[i]处取得的对象具有无序的段名称'å [英] The fetched object at index [i] has an out of order section name 'å

查看:183
本文介绍了在索引[i]处取得的对象具有无序的段名称'å的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Error fetching: Error Domain=NSCocoaErrorDomain Code=134060 

"The operation couldn’t be completed. (Cocoa error 134060.)" 
UserInfo=0x132eb960 {reason=The fetched object at index 76 
has an out of order section name 'å. Objects must be sorted by section name'}

我检查过,还有其他问题有相同的名字,

I checked and there are other questions with the same name, however in this case the problem appears due to diacritic alphabet symbols.

- (NSFetchedResultsController *)fetchedResultsControllerWithPredicate:
(NSPredicate *)aPredicate {
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];

    fetchRequest.entity = [Word MR_entityDescription];

    [fetchRequest setFetchBatchSize:20];
    [fetchRequest setPredicate:aPredicate];

    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name"
                                                                     ascending:YES
                                                                      selector:@selector(localizedCompare:)];

    fetchRequest.sortDescriptors = @[sortDescriptor];

    NSFetchedResultsController *aFetchedResultsController =
    [[NSFetchedResultsController alloc]
     initWithFetchRequest:fetchRequest
     managedObjectContext:localContext
     sectionNameKeyPath:@"name.stringGroupByFirstInitial" cacheName:nil];

    aFetchedResultsController.delegate = self;

    NSError *anyError = nil;
    if (![aFetchedResultsController performFetch:&anyError]) {
        NSLog(@"Error fetching: %@", anyError);
    }

    return aFetchedResultsController;
}

如果我替换 localizedCompare: compare:那么没有fetch错误,
,但是一些索引的顺序错误,没有显示段落。

If I replace localizedCompare: with compare: then there is no fetch error, however some indexes are in the wrong order, and there are no section shown.

推荐答案

不是解决方案本身,不幸的是...

Not a solution per se, unfortunately...

localizedCompare:不返回与从fetch请求返回到SQLite支持的持久存储使用本身的本地化比较的实现相同的结果。当涉及不寻常的字符时,这是特别明显。

localizedCompare: does not return the same results as what is returned from a fetch request to a SQLite backed persistent store using its own implementation of a localized compare. This is particularly evident when comes to "unusual" characters.

角色Æ是另一个可以在系统中引入扳手的程序,就像许多冰岛语和斯堪的纳维亚语字符一样。我一直在对这个问题敲我的头两年,没有效果。

The character Æ is another one that throws a wrench into the system, as do many Icelandic and Scandinavian language characters. I have been banging my head against this issue for two years to no avail.

否则,只要你没有这些不寻常的字符当下。我的解决方法是检测错误,将 sectionNameKeyPath 设置为 nil ,然后强制重新获取。不理想,也不高效,但比用户看不到任何东西更好。

Otherwise, it will work great as long as you don't have these "unusual" characters present. My workaround was to detect the error, set sectionNameKeyPath to nil, then force a re-fetch. Not ideal, nor efficient, but better than the user seeing nothing.

这篇关于在索引[i]处取得的对象具有无序的段名称'å的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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