0
+(NSString *)languageKey{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];


    NSString *lang = [languages objectAtIndex:0];    

    if([lang isEqualToString:@"en"])
      return @"en";
    else if([lang isEqualToString:@"ar"])
      return @"ar";

    return @"en";    

}

+(NSString *)localizedStringForKey:(NSString *)key{

    NSString *path;
    if([[self languageKey] isEqualToString:@"en"])
        path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
    else if([[self languageKey] isEqualToString:@"ar"])
        path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];

    NSBundle* languageBundle = [NSBundle bundleWithPath:path];
    NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];

    return str;
}

Sometimes i am getting wrong key here in iOS7 and below version working fine. Is this Xcode6.0 bug? How to get rid of this issue

Advance Thanks

Senthil
  • 510
  • 12
  • 28
  • We need to see the code where you store everything in user defaults. Honestly though, User Defaults probably isn't the correct place to store info like this – Joel Bell Nov 11 '14 at 22:30

1 Answers1

0

well Objective-C and Xcode-6 works fine with UserDefaults, in my experience with NSUserDefaults you need to be very careful with the way you save and retrieve data:

I Save data like this:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:@"data" forKey:@"key"];
[prefs synchronize];

And i retrieve data like this:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *theString = [prefs stringForKey:@"key"];

I Also see a [defaults synchronize] when you are retrieving the data, I think that is not necessary because you aren´t saving data, good luck.