Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define unichar constants in code

Tags:

objective-c

I'd like to do something like this:

const UniChar KA = 'か';

But XCode spits back "Multi-character constant".

I try to avoid using +characterAtIndex of NSString... I need this to iterate over the kana, like you can iterate over the alphabet (char myCharacter = 'A';)

I was looking at Objective c doesn't like my unichars? but it doesn't really solve it in a nice way for me.

Anyway, I'm trying to put the "tenten" and/or "maru" on top of か, た, etc like か→が, た→だ. Might be a ready made solution for that, in case anyone knows, that'll solve my problem as well.

like image 716
Jonny Avatar asked Jul 25 '11 07:07

Jonny


1 Answers

Source code is usually encoded as UTF-8, which means you can't use 16-bit character literals there. You need to use the escape sequence:

const UniChar KA = '\u30AB';

or specify the value numerically:

const unichar KA = 0x30AB;

(Note: I really have no idea if that's the correct code for the example character you gave.)

I think your only other option is to create a .strings file, which can and should be UTF-16 encoded, and then get the characters into your program using NSLocalizedString.

like image 111
jscs Avatar answered Oct 14 '22 08:10

jscs