Get Description of Emoji Character

character, emoji, string, swift

Solution

The Core Foundation function `CFStringTransform()` has transformations that determine the Unicode standard name for special characters. Example:

let c : Character = ""

let cfstr = NSMutableString(string: String(c)) as CFMutableString
var range = CFRangeMake(0, CFStringGetLength(cfstr))
CFStringTransform(cfstr, &range, kCFStringTransformToUnicodeName, false)
print(cfstr)

Output:

\N{SMILING FACE WITH OPEN MOUTH AND SMILING EYES}

See http://nshipster.com/cfstringtransform/ for more information about `CFStringTransform()`.

Problem

Each Emoji has a description that you can see in Mac OS's `⌃⌘Space` special character picker. There's a list of them here. Is there a way for me to query for this description in code (short of entering them all into a Struct)? I'd like to do something like: ``` let : Character = "" let desc: String = .description ``` and have `desc` resolve to `"SMILING FACE WITH OPEN MOUTH AND SMILING EYES"`.

Original source