Reputation: 1024
Hello i have a project using both objective-c and c++ , I never set any encoding and on the right panel of the file page it says “no specific encoding set”, but I’ve read that NSString is natively utf-16 so how would I translate a c++ string(utf-8) to NSString(utf-16)?
Upvotes: 0
Views: 480
Reputation: 10750
You can use the std::string::data()
method to get access to the raw bytes of the std::string
. Once you have that, you can use the init(bytes:length:encoding:)
constructor for NSString
to convert the raw bytes into a NSString
. Specify that the encoding is UTF-8.
Upvotes: 3