如何使用 Swift 2.0+ 在 Firebase 中存储和检索表情符号

How to store and retrive emojis in the Firebase using Swift 2.0+

你好谁能帮我看看如何在 Firebase 中存储表情符号?我正在尝试如下所示,但应用程序在我 运行.

时崩溃
let emoji = emoji.unicodeScalars
USER_REF.childByAppendingPath(friendUID as String).childByAppendingPath("messages").setValue(emoji, forKey: "emoji")

我的目的是将表情符号转换为 unicode,然后保存到 firebase 数据库中。

表情是unicode字符,可以按实际值存储。例如,一张笑脸是 1F642。

有一个关于该主题的 wiki,它有一个图表和交叉引用;搜索表情符号 (Unicode_block)

保存到 Firebase

let smiley = "\U0001F642"
smileyRef.setValue: smiley

从 Firebase 读取:

从 Firebase 读取值并将其填充到一个字符串中,使其成为一个 unicode 字符。然后显示字符串 UI,将该字符串分配给支持 unicode 的文本字段;在本例中为 NSTextField。

self.myTextField.stringValue = smiley;