Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7518395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:39+00:00 2026-05-30T01:44:39+00:00

I seem to be going in circles around this problem and I am heading

  • 0

I seem to be going in circles around this problem and I am heading no where now.

I am trying to force the language of my app (to swedish) as shown below.

@autoreleasepool {
    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"sv", nil] forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}

I have done it in the main method, so that preference is set as soon as the application is launched.

Then when i want to sort an array alphabetically i use NSSortDescriptor with selector localizedCaseInsensitiveCompare:.

NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"iName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];

NSArray * descriptors = [NSArray arrayWithObject:valueDescriptor];

self.ingredientsList = [NSMutableArray arrayWithArray:[self.ingredientsList sortedArrayUsingDescriptors:descriptors]];

But my problem is sorting with my local language does not happen the first time. But if I restart the app, the sorting is according to the language (Swedish). Why doesnt it happen the first time?

What am i doing wrong?

Help/suggestions will be appreciated.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:44:40+00:00Added an answer on May 30, 2026 at 1:44 am

    @DarkDust is correct. You should not try to modify the locale itself. That’s not under your control, and as you’re seeing, it doesn’t work very well. Most importantly, if you just want to modify one sort operation, this is a very big hammer to do that…. You could potentially play with the various localization Info.plist entries (particularly CFBundleLocalizations) to get this to work right, but not just to sort a single list.

    What you want to use is compare:options:range:locale:, which allows you to pass a specific locale. You can use this method inside of a sortedArrayUsingSelector: or sortedArrayUsingComparator:.

    Alternately, you could use a category to add a custom swedishCaseInsensitiveCompare: to NSString. You could then use NSSortDescriptor as you are currently.


    Example. ä is sorted after a in English, but after z in Swedish:

    @interface NSString (SwedishSorting)
    - (NSComparisonResult)caseInsensitiveSwedishCompare:(id)other;
    @end
    
    @implementation NSString (SwedishSorting)
    - (NSComparisonResult)caseInsensitiveSwedishCompare:(id)other;
    {
      return [self compare:other options:NSCaseInsensitiveSearch range:NSMakeRange(0, self.length) locale:[[NSLocale alloc] initWithLocaleIdentifier:@"sv"]];
    }
    
    @end
    
    int main(int argc, const char * argv[])
    {
    
      @autoreleasepool {
        NSArray *array = [@"Jag är en test av sortering" componentsSeparatedByString:@" "];
        NSArray *englishSort = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(caseInsensitiveCompare:)]]];
        NSLog(@"English = %@", englishSort);
    
        NSArray *swedishSort = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(caseInsensitiveSwedishCompare:)]]];
    
        NSLog(@"Swedish = %@", swedishSort);                                                                
      }
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where am I going wrong? This doesn't seem to work. I'm trying to specify
I seem to be going around in circles on something I know is really
There doesn't seem to be much info on this topic so I'm going to
Not too sure what's going on here as this doesn't seem like standard practise
I've been going over and over this in my head, and I can't seem
I seem to be going round in circles. I have a WPF application that
This is going to seem a very strange question but im just playing about
This is going to seem like a really silly question but I can't figure
Okay this is going to seem really dumb but bear with me please. A
I've spent quite a bit of time on this but seem to be going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.