如何使用nspredicate对非英语字符串进行排序?

Mer*_*ert 5 cocoa-touch core-data objective-c nssortdescriptor ios

我正在使用排序描述符对获取请求的结果进行排序.

NSFetchRequest* req = [[NSFetchRequest alloc] initWithEntityName:[MyEntity entityName]];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"property" 
                                                           ascending:YES 
                                                            selector:@selector(localizedCompare:)];
req.sortDescriptors = [NSArray arrayWithObject:descriptor];
return [self.managedObjectContext executeFetchRequest:req error:nil];
Run Code Online (Sandbox Code Playgroud)

问题是在列表的末尾列出了以'İ'等非英语字符开头的单词.这是一个土耳其字母,字母表如下:

A,B,C,Ç,D,E,F,G,Ğ,H,I,İ,J,K,L,M,N,O,Ö,P,R,S,Ş,T,U, Ü,V,Y,Z.

所以这封信是第12位.

我不知道为什么在获取对象后使用比较器.因此它适用于任何数组,但不适用于获取请求的排序描述符.

Bre*_*ddy 3

看看我的问题的详细信息NSFetchedResultsController vs UILocalizedIndexedCollat​​ion我展示了如何使用 UILocalizedIndexedCollat​​ion 正确生成字母表并使用基于 UILocalizedIndexedCollat​​ion 的正确排序方法进行排序。我的问题只是围绕着寻求更好的方法来做到这一点。

如果您不使用 UILocalizedIndexCollat​​ion,则应仅使用 localizedStandardCompare:而不是 WWDC 视频中提到的 localizedCompare 进行本地化。