views:

438

answers:

2

Hi,

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

+4  A: 

Check out the NSPredicate programming guide, but basically use [c] to ignore case:

@"firstName BEGINSWITH[c] $FIRST_NAME"
Ben Gottlieb
Hey Ben, Thanks!I could find the answer for my question. I posted it here. Cheers, VFN
vfn
+3  A: 

Hi Ben, 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 a "ORDER BY firstName ASC", and this comand 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 the the sortDescriptor as follow:


NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES selector:@selector(caseInsensitiveCompare:)];

I hope it will be useful for more people.

Cheers

vfn