DeZigny
DeZigny

Reputation: 1953

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 :/

Upvotes: 1

Views: 1222

Answers (1)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

use isEqualToString: for string comparisons.

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

Upvotes: 3

Related Questions