Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLocale Country Code and Name is Null

I am using the below code for Code and Country name but it returns null.

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
NSLog(@"Language : %@ Lang2 : %@",[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0],[[NSLocale preferredLanguages] objectAtIndex:0]);
NSLog(@"Locale:%@ Code:%@ Name%@:", locale, countryCode, country);

developmentRegion = English;
        hasScannedForEncodings = 0;
        knownRegions = (
            en,
            Base,
            fr,
            de,
            nl,
            ja,
            es,
            tr,
            it,
            pl,
            pt,
        );

Logs : Locale:<__NSCFLocale: 0x7fbef943f810> Code:(null) Name(null)

Language : nl Lang2 : nl

enter image description here

Tested both on device and simulator.i don't know whats going on here.It should work fine.Please let me know if you guys have any idea.i am using xcode 6.4.

enter image description here

like image 859
iYousafzai Avatar asked Jul 27 '15 10:07

iYousafzai


1 Answers

Finally found the bugger.

I tested the above code in another test project and was working fine but not in my current project. So i used the developer tool FileMerge and compared the two and found a difference in the below line.(xcshareddata->xcschemes->****.xcscheme).

enter image description here

I don't know how the language = "nl" got there may be due to a bad merge but rolling back and re-merge didn't work either.

Manually removing the line solved my Ghostly Problem :)

like image 79
iYousafzai Avatar answered Oct 19 '22 15:10

iYousafzai