I'm using stringWithFormat @"%ls" to do it and I only see the first character copied, which makes me think it's still assuming it's a single byte char.
Any ideas?
I'm using stringWithFormat @"%ls" to do it and I only see the first character copied, which makes me think it's still assuming it's a single byte char.
Any ideas?
For resolve this task I done this:
Use
initWithBytes:length:encoding
. You will have to know the encoding thatwchar_t
uses, I believe it is UTF-32 on Apple platforms.In general, I suggest avoid using
wchar_t
if at all possible because it is not very portable. In particular, how are you supposed to figure out what encoding it uses? (On Windows it's UTF-16LE or UTF-16BE, on OS X, Linux, and iOS it's UTF-32LE or UTF-32BE).Following code worked for me:
Notice the "%S" part. That made the whole difference.
From the Foundation Constants Reference, I think the function
NSHostByteOrder()
is the right way:Probably best to put them in an NSString category.