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.
我做了一些谷歌搜索,我读完了 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:)];
希望对更多人有用.
这篇关于iPhone CoreData - 如何获取托管对象,并在忽略大小写的情况下对它们进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!