0

Non-latin text outputs very strange way in XCode debug console. How make it right?

For example: Проверьте давление экрана. became –ü—Ä–æ–≤–µ—Ä–∫–∞ –¥–∞–≤–ª–µ–Ω–∏—è —ç–∫—Ä–∞–Ω–∞

(Help me please improve my question because my english is not good. Let me know If it's hard to understand what I wrote here.)

- (id) initWithDictionary:(NSDictionary*)dictionary
{
    //...
    self.title = [dictionary objectForKey:@"Заголовок"] ; // dictionary from plist encoded in UTF8
    //...
    return self;
}
- (void) log
{
    NSString *class = NSStringFromClass([self class]);
    NSString *sel   = NSStringFromSelector(_cmd);
    NSLog(@"%@:%@:%@", class, title_, sel);
}

title_ is iVar NSString loaded from plist. It's used as title of uiviewcontroller and works fine on iPhone & iPad.

Oleg Trakhman
  • 2,082
  • 1
  • 17
  • 35
  • Looks like the debug console doesn't support Unicode. That looks like raw UTF-8 rendered into latin-1. – Managu Jun 08 '12 at 14:37
  • http://stackoverflow.com/questions/4606570/os-x-terminal-utf-8-issues may be relevant. – Managu Jun 08 '12 at 14:39
  • Thank you, Managu! If you know that for sure, write(copy-paste) it as answer so I can accept it, please. – Oleg Trakhman Jun 08 '12 at 14:39
  • I don't really know, just guessing. I've never used XCode. – Managu Jun 08 '12 at 14:42
  • It's not about terminal, it's about debugger console inside XCode (although these problems may be related) – Oleg Trakhman Jun 08 '12 at 14:42
  • As another thought: the gibberish might instead be raw UTF-16 in latin-1. It could possibly be that if you output it as UTF-8, it would display properly. – Managu Jun 08 '12 at 14:48
  • How are you logging to the console? Are you using NSLog() or some other logging method? I thought since Xcode 3.0 this was no longer a problem when using NSLog() but I've never had reason to try it. – Joshua Nozzi Jun 08 '12 at 15:04
  • What are "class," "title_," and "sel"? Are they all NSString instances? – Joshua Nozzi Jun 08 '12 at 15:27
  • title_ is the only non-latin string from them. title_ is NSString. class and sel don't cause problems at all. – Oleg Trakhman Jun 08 '12 at 15:46

2 Answers2

1

Since I changed debugger from lldb to gdb output had become OK. So, something wrong must be with lldb.

In xcode 4: Menu -> Product -> Manage Schemes... Then tap Edit button -> Run Your.app (Left panel) -> Debugger -> change it from LLDB to GDB.

Oleg Trakhman
  • 2,082
  • 1
  • 17
  • 35
0

I thought this wouldn't be a problem as of Xcode 3 but I guess I thought wrong.

Ugly trick for logging: Maybe try NSString's -cStringUsingEncoding: with different logging format to try to force the correct encoding to be displayed. I don't know if this will work:

NSLog(@"%S", [title_ cStringUsingEncoding:NSUnicodeStringEncoding]);
Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • 1
    Julian: Sorry, but that's incorrect. NSUnicodeStringEncoding is a little-endian UTF-16 with BOM. "%S" is exactly the right format specifier. See also: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html – Joshua Nozzi Jan 11 '13 at 17:18