Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:50:53+00:00 2026-06-04T14:50:53+00:00

Im my iOS 5.1 application, I use a 3rd party library which uses wchar_t

  • 0

Im my iOS 5.1 application, I use a 3rd party library which uses wchar_t for strings. This works fine internally, but I sometimes need to create an NSString for such string. I can use the following API:

- (id)initWithBytes:(const void *)bytes length:(NSUInteger)length encoding:(NSStringEncoding)encoding

But what encoding am I supposed to use? Since wchar_t in iOS is 32 bits, the candidate encodings are:

NSUTF32StringEncoding
NSUTF32BigEndianStringEncoding
NSUTF32LittleEndianStringEncoding

Which byte order am I supposed to use? Should I use the encoding byte order corresponding to the result of long NSHostByteOrder()?

And by the way, which byte order is NSUTF32StringEncoding representing? Is it going to examine the bytes and deduce the byte order? And what will it yield when converting from NSString with getBytes:maxLength:usedLength:encoding:options:range:remainingRange:?

Note that I am not concerned with data exchange between platforms here (though I may have to face that issue too someday).

Googling around didn’t help much.

My hunch is that this is compiler-defined, e.g. what encoding is used by my compiler (CLang) when I write:

wchar_t *s = L"string with non ascii unicode characters such as éèüçß";

Of course it’s easy enough to write a small sample program and find out, but I’d like a solution that doesn’t rely on the specific implementation of my compiler.

If you believe I am confused, that’s because I am a bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:50:54+00:00Added an answer on June 4, 2026 at 2:50 pm

    This is why wchar_t is impossible to recommend, except when you need to work directly with the Windows API.

    On iOS, wchar_t is UTF-32 with the native byte order. This is technically not the same thing as NSUTF32StringEncoding, which indicates either byte order with a BOM.

    Here’s some copy pasta from the last time I answered this question (link):

    #include <machine/endian.h>
    #if BYTE_ORDER == BIG_ENDIAN
    #define WCHAR_ENCODING NSUTF32BigEndianStringEncoding
    #elif BYTE_ORDER == LITTLE_ENDIAN
    #define WCHAR_ENCODING NSUTF32LittleEndianStringEncoding
    #endif
    

    The problem with using NSUTF32StringEncoding is that it will only work for converting wchar_t to NSString, but not necessarily the other way around. It will stick a BOM on the front (undesirable) and it may even give you data in the wrong endian.

    It is also possible that using NSUTF32StringEncoding will cause errors even going from wchar_t to NSString, but that is extremely unlikely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using CoreData in an iOS application. Everything works fine except for fields
I am developing an IOS application, which uses web services (SOAP/WSDL). I have built
I want to use Leptonica library in my iOS application for image processing and
Hello i actually develop a Ios application This application use a PHP webservice to
I'm using the OAuthConsumer in my iOS application which makes use of the Tumblr
I have an iOS application that use an Web Server to grab Sports information.
I want to use HelveticaNeue-UltraLight in my ios application. I'm adding the font file
I have a C2-DB9 serial cable from Redpark for use with an iOS application
I'm building a PhoneGap 1.5 (Cordova) application for iOS and want to use the
I create a drawing iOS application in which I would like to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.