unicode warning in ObjC

  • The following statement:
    unichar character = [[NSString stringWithUTF8String: "\u03C0"]
    characterAtIndex: 0];
    gives me a warning message in XCode:
    warning: universal character names are only valid in C++ and C99

    This confuses me. I was under the impression that NSString can
    contain and can handle characters in 16bit Unicode. Either I am doing
    something wrong or I misunderstood something.

    What do I have to do to get \u03C0 (the character pi) correctly and
    without warning in my NSString's?

    Hans van der Meer
  • > unichar character = [[NSString stringWithUTF8String: "\u03C0"]
    > characterAtIndex: 0];

    NSString has no problem with storing/representing the character, it's
    the compiler that doesn't like your C string literal. This is what
    you want:

    unichar character = [[NSString stringWithFormat:@"%C", 0x03C0]
    characterAtIndex:0];

    But really, why go through NSString if you already know the constant?
    Eg:

    unichar character = 0x03C0;

    ~Martin
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today