4

Hello All,

I have a problem regarding Unicode characters. I'm able to append Apple Art Work Unicode Characters in UITextView. Like this : -

self.textView.text = @"\ue00A";

It is Okay. But now i have many Unicodes Characters which're not in Apple art work.
One of them is U+1F3C7
Now I'm trying to show it in UITextView.

self.textView.text = @"\u1f3c7"; 

Then it is showing me an Special Character instead of Emoji.
Unicode Emoji

This is the Emoji Icon of this Unicode But it is showing me Ἴ7.

Apple doesn't support all Unicode Characters ?
How can I add my own emojies in my application ?

Let me know if my question is not clear for you.

TheTiger
  • 13,264
  • 3
  • 57
  • 82
  • Try this http://code.google.com/p/emotionlabel/ – Sumanth Aug 27 '12 at 11:05
  • See also http://stackoverflow.com/questions/9352753/which-unicode-versions-are-supported-in-which-os-x-and-ios-versions – tripleee Aug 27 '12 at 11:31
  • When any body down vote any question please add a comment WHY ???? Other wise you're doing down voting for your fun. – TheTiger Sep 17 '12 at 13:47
  • **Jon Hanna's** answer is perfect U+1F3C7 Unicode will be written as \U0001F3C7 not as \u1f3c7. Test it with a real device they don't work properly on Simulator. – TheTiger Jan 31 '19 at 12:23

1 Answers1

8

Doesn't Objective-C use UTF-16 internally, like Java and C#?

If so, then U+1F3C7 wouldn't be "\u1f3c7", but the surrogate-pair, "\uD83C\uDFC7".

Otherwise, there has to be some way to indicate a higher character, because "\u1f3c7" is the same as "\u1f3c" + "7", which is Ἴ7 (capital iota with psili and oxia, then 7).

Edit: After some discussion between the OP and myself, we figured out that the way to do this in Objective C is one I know as the C++ way:

"\U0001F3C7"

(\uXXXX with a small u and 4 hex digits works if it fits in thos 4 hex digits, \UXXXXXXXX with a capital U and 8 hex digits works for everything, but is longer to type).

Now our friend just needs to deal with the matter of font support, which alas is another problem in getting this to actually look as he wants.

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251
  • Thanks for quick response. So I'll have to change my string in UTF-16 ? Which link you gave this is for MAC. Okay i try it for IOS. – TheTiger Aug 27 '12 at 11:32
  • I know nothing of objective C, so I'm basing my answer on my Unicode knowledge (they aren't "Apple's Unicode characters", they belong to all of us) and a bit of transference from Java and C# alone. If `"\uD83C\uDFC7"` works, you'll know you're on the right track. The link I found just by googling for something to turn a code-point into UTF-16 in objective-C, but that bit's just a "what about trying..." rather than based on stuff I know, like that U+1F3C7 in UTF-16 is D83C followed by DFC7 – Jon Hanna Aug 27 '12 at 11:49
  • I tried this `const char *ch = (char *)@"U+1F3C7"; NSString *str = [NSString stringWithCString:ch encoding:NSUTF16StringEncoding];` now when i print `str` it is `貜䔁젇` ... :( – TheTiger Aug 27 '12 at 11:49
  • Did you try `self.textView.text = @"\uD83C\uDFC7"`? – Jon Hanna Aug 27 '12 at 11:51
  • (they aren't "Apple's Unicode characters", they belong to all of us) - I think apple has limit of unicode characters. – TheTiger Aug 27 '12 at 11:51
  • In objective see we can not assign it directly self.textView.text = @"\uD83C\uDFC7"; It gives error. – TheTiger Aug 27 '12 at 11:52
  • 2
    The `U+1F3C7` syntax is a universal way of talking about unicode characters across different technology and languages, rather than programming code. What's the error. Sadly, I've the unicode knowledge and you've the obj-c knowledge, but the error might help someone who knows both give you your answer. – Jon Hanna Aug 27 '12 at 11:53
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15849/discussion-between-vakul-saini-and-jon-hanna) – TheTiger Aug 27 '12 at 11:55