iPhone CoreData - How to fetch managed objects, and sorting them ignoring case?

vfn picture vfn · Jan 6, 2010 · Viewed 8.6k times · Source

Does anyone know how to fetch some results sorting them alphabetically but ignoring case?

Answer

vfn picture vfn · Jan 7, 2010

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 speaking, I need an ORDER BY firstName ASC, and this command must be case insensitive for my usage.

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.