Search code examples
objective-cnslocale

Can't check NSLocaleLanguageCode value by IF condition!


I'm displaying localLanguage and got a value of en which is correct 100% based on my device selected language.

Then I checked localLanguage value to do some alignments, but the problem is not falling in the en condition! Its always falling in ELSE condition! Am I checking the value incorrectly?

NSString *localLanguage = [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode];
NSLog(@"%@",localLanguage);

if (localLanguage == @"en") {
  NSLog(@"EN");
} else if (localLanguage == @"ar") {
  NSLog(@"AR");
} else {
  NSLog(@"XX");
}

Please help :/


Solution

  • use isEqualToString: for string comparisons.

    if ( [localLanguage isEqualToString:@"en"] ) {
        ....