Yes, you can malloc()
a buffer of the appropriate size. You have to free()
the buffer
when it is no longer used, because ARC does not manage malloc
ed memory.
Alternatively, create an NSData
object with the UTF-16 encoding:
NSString *string = @"H€llö Wörld";
NSData *data = [string dataUsingEncoding:NSUTF16LittleEndianStringEncoding];
const unichar *charsPtr = [data bytes];
charsPtr
is valid as long as data
exists, i.e. as long as you keep a strong reference to it.