Search code examples
iosswiftfirebaseios9

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


Hi anyone can please help me how to store Emojis in Firebase? I am trying like below but the app is crashing while i run.

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

My intention here was converting an emoji into unicode, and saving in to the firebase database.


Solution

  • Emoticons are unicode characters and can be stored by their actual value. So for example a smile face is 1F642.

    There's a wiki on that topic it has a chart and cross reference on it; search for Emoticons (Unicode_block)

    To save to Firebase

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

    To read from Firebase:

    Read the value from Firebase and stuff it into a string that will allow it to be a unicode char. Then to present the string UI, assign that string to a text field that supports unicode; NSTextField in this case.

    self.myTextField.stringValue = smiley;