NSLocale国家代码和名称为空

ihy*_*ihy 8 ios nslocale xcode6

我使用下面的代码和国家名称,但它返回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,
        );
Run Code Online (Sandbox Code Playgroud)

日志:区域设置:<__ NSCFLocale:0x7fbef943f810>代码:(null)名称(null)

语言:nl Lang2:nl

在此输入图像描述

在设备上测试了和simulator.i不知道什么在here.It去应该工作fine.Please让我知道,如果你们有任何idea.i我使用的Xcode 6.4.

在此输入图像描述

ihy*_*ihy 3

终于找到了坏人。

我在另一个测试项目中测试了上面的代码并且工作正常,但在我当前的项目中则不然。因此,我使用开发工具 FileMerge 并比较了两者,发现以下行中存在差异。(xcshareddata->xcschemes->****.xcscheme)。

在此输入图像描述

我不知道 language =“nl” 是如何到达那里的,可能是由于合并错误,但回滚并重新合并也不起作用。

手动删除线解决了我的幽灵问题:)