如何获得 Apple 表情符号名称而不是 Unicode 名称?

gol*_*alk 4 emoji swift swift-string

我看到字符查看器中显示的表情符号的 Unicode 名称与其 Apple 名称不同。如何使用 Swift 获取表情符号的 Apple 名称?

例子:

表情符号:

Unicode 名称(通过 获得.applyingTransform(.toUnicodeName, reverse: false)):

张开嘴和微笑的眼睛的笑脸

Apple 名称(来自 macOS Character Viewer):

眯着眼睛咧嘴笑的脸

Rob*_*ier 7

第一个是 Unicode 名称,但正确的名称是:

SMILING FACE WITH OPEN MOUTH AND SMILING EYES
Run Code Online (Sandbox Code Playgroud)

它是大写的事实很重要。它是一个 Unicode 标识符。它是永恒的,也是独一无二的。(它真的是永久性的,即使他们在“垂直右白色透镜状BRAKCET的演示表格”中拼错了“BRAKCET”这样的词,这个名字也是永远的)。

第二个名称是“Apple 名称”。这些是本地化名称。在 Mac 上,英文版本存储在:

/System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/AppleName.strings
Run Code Online (Sandbox Code Playgroud)

您可以使用 转储此文件plutil,或使用 PropertyListDecoder 读取它。

$ plutil -p AppleName.strings
{
  "?" => "wavy dash"
  "??" => "red double exclamation mark"
  "??" => "red exclamation mark and question mark"
  "*??" => "keycap asterisk"
  "#??" => "number sign"
  "??" => "part alternation mark"
  "©" => "copyright sign"
  ...
Run Code Online (Sandbox Code Playgroud)

也就是说,除非您绝对需要匹配 Apple,否则我建议使用CLDR(Common Locale Data Repository)注释短名称。这是本地化名称的 Unicode 来源。不过,它们并没有被承诺是独一无二的。它们最大的目的是支持文本转语音。

对于 XML 中的当前列表,在GitHub 上最方便。或者您可以浏览v37 表或下载原始数据