"localizedStandardCompare" depends on the language preference of the iOS device -
nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"name" ascending:yes selector:@selector(localizedstandardcompare:)]; [fetchrequest setsortdescriptors:[nsarray arraywithobjects:sortdescriptor,nil]];
i working on app has list of names, names in Íslenska(icelandic) language. above code works fine if language selected apps in settings Íslenska(icelandic) sort descriptor fails if language other Íslenska(icelandic).
is there way resolve dependency problem?
this should create sortdescriptor
compare strings using is_is
locale.
nssortdescriptor* sortdescriptior =[[nssortdescriptor alloc] initwithkey:@"name" ascending:yes comparator:^(nsstring* str1, nsstring* str2) { static nsstringcompareoptions comparisonoptions = nscaseinsensitivesearch | nsnumericsearch | nswidthinsensitivesearch | nsforcedorderingsearch; return [str1 compare:str2 options:comparisonoptions range:nsmakerange(0, str1.length) locale:[nslocale localewithlocaleidentifier:@"is_is"]]; }];
Comments
Post a Comment