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

标签 swift emoji swift-string

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

示例:

表情符号:😄

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

smiling face with open mouth and smiling eyes



Apple 名称(来自 macOS Character Viewer):

grinning face with squinting eyes

最佳答案

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

SMILING FACE WITH OPEN MOUTH AND SMILING EYES
它是大写的事实很重要。它是一个 Unicode 标识符。它是永恒的,也是独一无二的。 (它真的是永久性的,即使他们在“垂直右白色透镜状BRAKCET的演示文稿”中拼错了“BRAKCET”这样的词,这个名字也是永远的)。
第二个名称是“Apple 名称”。这些是本地化名称。在 Mac 上,英文版本存储在:
/System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/AppleName.strings
您可以使用 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"
  ...
也就是说,除非您绝对需要匹配 Apple,否则我会推荐 CLDR (Common Locale Data Repository) 注释短名称。这是本地化名称的 Unicode 来源。不过,它们并没有被 promise 是独一无二的。它们最大的目的是支持文本转语音。
对于 XML 中的当前列表,最方便的是 GitHub .或者您可以浏览v37 table或下载 raw data .

关于swift - 如何获得 Apple 表情符号名称而不是 Unicode 名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61348244/

相关文章:

swift - SwiftUI 中的非 View 子类是否可以访问 environmentObject

python - 如何在python 3中打印红心

database - 为什么总是存储表情符号的简称?

swift - 什么是 String.Encoding.unicode?

嵌套数组上的 Swift 相等运算符

swift - 删除最后一行并同时加载多行

Swift 用条件替换字符串的出现

ios - 在 swift 中使用 PHImageManager (requestAVAssetForVideo)

ios - 在模拟器 Swift 上运行自定义键盘时出错