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

﹥>﹥吖頭↗ 提交于 2019-11-26 21:58:21

问题


This question already has an answer here:

  • Print unicode character from variable (swift) 6 answers

How do you convert unicode emoji stored as a string (e.g. 1f564) 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}"

Thanks


回答1:


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

let myStr = "1f564"
let str = String(UnicodeScalar(Int(myStr, radix: 16)!)!)


来源:https://stackoverflow.com/questions/32555145/convert-unicode-e-g-1f564-to-emoji-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!