Andrew Varvel Andrew Varvel - 1 year ago 267
Swift Question

Convert Unicode (e.g. 1f564) to Emoji in Swift

How do you convert unicode emoji stored as a string (e.g.

) to an emoji that could be placed on a UILabel?

let myString = "1f564"

I've seen the use of the escape character but I can't insert variables to replace the characters.

let flag = "\u{1f1e9}\u{1f1ea}"


Answer Source

This works. I don't know if there is anything more direct:

let myStr = "1f564"
let str = String(UnicodeScalar(Int(myStr, radix: 16)!))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download