1

I have a NSDictionary like this

NSDictionary *result = [[NSDictionary alloc]
                        initWithObjectsAndKeys:
                        @"USA.png", @"США",
                        @"EC.png", @"ЕС",
                        @"Russia.png", @"Россия",
                        @"Brazil.png", @"Бразилия",
                                            ....... and more ......
                        nil];

and i want to get values from this dictionary by sending string key eventCountry from XML parser.

NSString *countryImageString = [self.countrySet objectForKey:event.eventCountry];
        if (countryImageString.length == 0) {
            calCell.countryImageView.image = [UIImage imageNamed:@"Unknown.png"];
        } else {
            calCell.countryImageView.image = [UIImage imageNamed:countryImageString];
        }

In NSLog my NSDictionary looks like

"\U0410\U0432\U0441\U0442\U0440\U0430\U043b\U0438\U044f" = "Australia.png";
"\U0410\U0432\U0441\U0442\U0440\U0438\U044f" = "Austria.png";
"\U0410\U043d\U0433\U043b\U0438\U044f" = "England.png";
"\U0410\U0440\U0433\U0435\U043d\U0442\U0438\U043d\U0430" = "Argentina.png";
"\U0411\U0435\U043b\U044c\U0433\U0438\U044f" = "Belgium.png";
"\U0411\U0440\U0430\U0437\U0438\U043b\U0438\U044f" = "Brazil.png";

but eventCountry is in UTF-8. How can i fill correctly plist file without \U0410\U0432\ characters or convert encoding on the fly?

Leshiy
  • 13
  • 2

1 Answers1

0

It's just the description method (which NSLog() uses for printing objects) of your dictionary or array being dumb and unhelpfully escaping the text. The strings will be correct when written to a file.

  • But NSLog displays eventCountry correctly. I think there is a problem with comparing different encoded strings. – Leshiy Aug 10 '13 at 09:51
  • @user2670169 So, did you try to actually write it to a file and have a look at it with a text editor? –  Aug 10 '13 at 09:53
  • 1
    @user2670169: Only the NSLog output for NSDictionary and NSArray uses (for whatever reason) the [Old-Style ASCII Property Lists](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/OldStylePlists/OldStylePLists.html#//apple_ref/doc/uid/20001012-BBCBDBJE) format. NSString logs nicely at UTF-8. – Martin R Aug 10 '13 at 09:55
  • @MartinR Well, then it's not actually `NSLog()` that's being unhelpful, but `- [(NSArray/NSDictionary) description]`, is it right? –  Aug 10 '13 at 09:58
  • @H2CO3: Yes exactly, I was just simplifying my remark. – Martin R Aug 10 '13 at 10:01
  • @MartinR No, it's just that ***I*** was incorrect with my answer :) –  Aug 10 '13 at 10:01
  • I used TouchXML and it was ok, but later replaced it with AFNetworkingXML for asynchronous requests – Leshiy Aug 10 '13 at 10:14