Reputation: 493
When I test using emoji as variable names in Swift (XCode 7.2), I have major problems in that only some emoji work. I've determined that it is because some emoji include their base Unicode codepoint followed by a "variation selector".
Is there a way to insert characters into my source code without the unprintable variation selector coming along with the ride and ruining my code?
This mostly seems to be the fault of Apple's implementation of Unicode, where using the character selection pane to insert ♣️ inserts the codepoint for Clubs followed by the variation selector for "use the emoji version, not the plain text style". Inserting ♣ injects both the Clubs codepoint and the "use the text-style" selector.
If not, is there a list of characters to avoid using in variable names? So far, I've found anything involving a card suit to be problematic, as well as any human-like emoji that Apple has enabled for skin tone selection.
Upvotes: 1
Views: 1076
Reputation: 21289
You can input individual code points using the "Unicode Hex Input" input source that comes with Mac OS X. See this guide for enabling and using it.
In general, you probably want to avoid non-ASCII identifiers for exactly the reasons you mention. There are many other examples where non-ASCII identifiers can cause problems, and they offer almost no practical benefit.
Upvotes: 2