vfn*_*vfn 31 sorting iphone core-data nssortdescriptor
有谁知道如何获取一些结果按字母顺序排序但忽略大小写?
vfn*_*vfn 78
谢谢你的回复,但我需要对一个简单的"查询"忽略大小写的结果进行排序.您的建议适用于搜索和比较.
SQL说,我需要一个ORDER BY firstName ASC,这个命令必须对我的用法不区分大小写.
我做了一些谷歌搜索,我结束了阅读NSSortDescriptor类参考,我可以找到我的问题的答案.解决方案是将选择器设置为排序描述符,如下所示:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES selector:@selector(caseInsensitiveCompare:)];
我希望它对更多人有用.
Mon*_*art 10
如果应用程序已本地化为多种语言,请考虑使用localizedCaseInsensitiveCompare:选择器而不是caseInsensitiveCompare.这将有效避免字母'é'在字母'e'之后.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
查看NSPredicate编程指南,但基本上使用[c]忽略大小写:
@"firstName BEGINSWITH[c] $FIRST_NAME"
| 归档时间: | 
 | 
| 查看次数: | 8530 次 | 
| 最近记录: |