iPhone CoreData - 如何获取托管对象,并排序它们忽略大小写? [英] iPhone CoreData - How to fetch managed objects, and sorting them ignoring case?

查看:144
本文介绍了iPhone CoreData - 如何获取托管对象,并排序它们忽略大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何获取一些结果按字母顺序排序,但忽略大小写?

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屋!

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