Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

objective c - Unicode characters don't display properly in NSLog output

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 = "U043aU043eU0448U043aU0430";
    "U0441U043eU0431U0430U043aU0430" = dog;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...