objective c - Creating a NSSortDescriptor using a given locale -
i'm using nsfetchrequest access persistent store, pass nssortdescriptor. content sorted in norwegian, want always sort using "nb-no" locale, no matter user preferences.
right i'm using system locale determine sorting:
nssortdescriptor *sorting = [nssortdescriptor sortdescriptorwithkey:@"title" ascending:yes selector:@selector(localizedcaseinsensitivecompare:)];
what's simplest/cleanest way this?
select project--> info ---> set "localization native development region" "nb-no". dont forget add specific localisaation files project. :)
if want sort according device language below code
// using fetch request -(nsfetchrequest*)returnfetchrequest:(nsfetchrequest*)fetchrequest { nsentitydescription *entity = [nsentitydescription entityforname:@"your entity name" inmanagedobjectcontext:your context]; [fetchrequest setentity:entity]; // edit sort key appropriate. nssortdescriptor *sortdescriptor = [nssortdescriptor sortdescriptorwithkey:[nsstring stringwithformat:@"%@",nslocalizedstring(@"title", nil)] ascending:yes]; nsarray *sortdescriptors = [nsarray arraywithobjects:sortdescriptor, nil]; [fetchrequest setsortdescriptors:sortdescriptors]; return fetchrequest; }
Comments
Post a Comment