NSLog outputs unicode characters as garbage when debugging on the iPhone
EDIT: NSLog output works well in the simulator, but doesn’t work when connected to a real device. And it seems that it is a bug — http://openradar.appspot.com/11148883. Also it happens that it is related to the LLDB, switching Xcode to GDB resolves the problem. Either it’s possible to JetBrain’s AppCode, which works well with the LLDB.
I have a bunch of unicode strings in the application, and if I try to output any of those strings using something like NSLog(@”%@”, aString) then all the ASCII characters in the string will be printed fine but all the cyrillic letters will be messed up, so instead of
newLocation: coordinate:60.019584,30.284954 'Удельная'
newLocation: coordinate:60.019584,30.284954 '–ü–æ–∫–ª–æ–Ω–Ω–æ–≥–æ—Ä—Å–∫–∞—è'
And that’s quite hard to do any debugging with that kind of output. And because that app is targeted for the Russian market only I can’t just change locale and use English strings.
So I wonder if there any way to make NSLog work well with unicode characters? And I’m looking only for some kind of one-liner solution, I know that there are some ways to write half a page of code and output unicode chars, but I’m looking for something shorter. Ideally I’m looking for some method of NSString that will make it all work. e.g.
NSLog(@"%@", [aString someThingThatMakesUnicodeWorkWithXcodeConsole]);
5 Solutions Collect From Internet About “NSLog outputs unicode characters as garbage when debugging on the iPhone”
As far as I know it is relevant to NSLog() and LLDB on some Xcode versions. Have a try with one of these solutions:
- Check log in Xcode Organizer >> Devices >> your device >> Console.
- Use GDB as your debugger instead of LLDB if you are using the latter one. This can be changed from the schema options. Please refer to the steps in the comment by “cocos2d man” below.
- Upgrade to Xcode 4.3.2. Some people say it solved this issue, but I haven’t confirmed this myself.
Yes, obviously you can create a string that will contain and output cyrillic letters. When I was learning Objective-C, I had the same problem in the begining(I’m as well was working with Russian words and stuff like that). So solution is to convert the string to other format like this:
NSString *string = [NSString stringWithCString:"Привет, как дела?" encoding:4]; NSLog(@"%@", string);
NSString *string = [NSString stringWithUTF8String:"Этот вариант короче!"]; NSLog(@"%@", string);
Hope it helps you!
P.S It means that you need to make create your strings as C-Style Strings, and set their encoding parameter to 4(UTF-8). You can see all list of avaliable parameters in the documentation to NSStringEncoding in NSString.
Try to convert it in to UTF8 string.
NSString *str = [aString UTF8String] NSLog(@"%@", str);
Hope this helps.
Try putting it like
you can convert it in UTF8 string. This could get you through.
NSString *str = [aString UTF8String];
Hope this helps.
Try this. It works for me.
NSLog(@"%@", [NSString stringWithCString:[[places description] cStringUsingEncoding:NSASCIIStringEncoding] encoding:NSNonLossyASCIIStringEncoding]);
- How do I populate two sections in a tableview with two different arrays using swift?
- Pass a variable between lots of UIVIewControllers
- How to display compiler output or custom build steps output when building with xcode?
- iOS how to set app icon and launch images
- Cannot install Lxml on Mac os x 10.9
- IPv6 App Store Rejection
- UIWebView throwing exception for
- Adding a view on top of a MPMoviePlayerController
- NSData and Uploading Images via POST in iOS
- PDF editing with iPhone sdk
- Objective C: How to add Shadow effect to navigation bar and table cells
- Storyboard reference on iOS below 9.0
- JavaDoc-like documentation for Objective-C in Xcode?
- UITableView – Multiple selection AND single selection
- Copying of NSMutableArray from one viewcontroller to another viewcontroller?