iPhone CoreData - 如何获取托管对象,并排序它们忽略大小写? [英] iPhone CoreData - How to fetch managed objects, and sorting them ignoring case?
问题描述
有人知道如何获取一些结果按字母顺序排序,但忽略大小写?
Does anyone know how to fetch some results sorting them alphabetically but ignoring case?
推荐答案
谢谢您的回复,我需要排序一个简单的查询忽略大小写的结果。您的建议适用于搜索和比较。
Thank you for your reply, but I need to sort the result of a simple "query" ignoring case. Your suggestion applies for searching and comparing.
SQL,我需要一个 ORDER BY firstName ASC
必须对我的使用情况不区分大小写。
SQL speaking, I need an ORDER BY firstName ASC
, and this command must be case insensitive for my usage.
我完成了一些Google搜索,我结束了阅读 NSSortDescriptor类引用,我可以找到我的问题的答案。解决方案是将排序描述符的选择器设置如下:
I have done some Googling and I ended reading the NSSortDescriptor Class reference, and I could find the answer for my question. The solution is setting a selector to the sort descriptor as follow:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES selector:@selector(caseInsensitiveCompare:)];
我希望它对更多的人有用。
I hope it will be useful for more people.
这篇关于iPhone CoreData - 如何获取托管对象,并排序它们忽略大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!