Unicode characters don't display properly in N

2019-01-19 09:09发布

问题:

I want to program my own Eng-Rus dictionary with personalised entries. Studying the topic I wrote this method (in the purpose of learning) - and I cannot output the NSMutableDictionary in Russian TO CONSOLE. Look at the code and the console output. I've tried to disable LLDB to GDB with no luck. The encoding pref is UTF8 (xcode 4.6.3). So, I think I have a "programmer" issue - i.e I just don't know something. I still learning, so need your help, friends...

-(NSString*) dicto
{
    NSString *vic;
    NSMutableDictionary *dictos = [[NSMutableDictionary alloc]initWithCapacity:10] ;

    [dictos setValue:@"кошка" forKey:@"cat"]; //at the console output below NO Russian
    [dictos setValue:@"dog" forKey:@"собака"]; //at the console output below NO Russian

    NSArray *final=[dictos allKeys];
    id vid =[final objectAtIndex:1];
    NSLog(@"vid is %@",vid); // prints in Russian
    NSLog(@"%@", dictos); //this line probably has an issue  
    vic=vid;
    return vic; //the label.text in sender (=iphone simulator) prints Russian   
}

Console Output (lower window in XCode)

2013-08-04 23:20:33.958 helloWorldToConsolFromNSLog[17718:c07] vid is собака
2013-08-04 23:20:33.958 helloWorldToConsolFromNSLog[17718:c07] {
    cat = "\U043a\U043e\U0448\U043a\U0430";
    "\U0441\U043e\U0431\U0430\U043a\U0430" = dog;
}

回答1:

NSLog uses the description method for printing an NSDictionary (or NSArray), and that prints all non-ASCII characters in the \Unnnn escaped form.

NSLog and description should only be used for debugging output, so this no problem at all. All keys and values are stored correctly.