How can I get the Unicode codepoint represented by an integer in Swift?

孤街浪徒 提交于 2019-12-04 03:43:13

If you look at the enum definition for Character you can see the following initializer:

init(_ scalar: UnicodeScalar)

If we then look at the struct UnicodeScalar, we see this initializer:

init(_ v: UInt32)

We can put them together, and we get a whole character

Character(UnicodeScalar(65))

and if we want it in a string, it's just another initializer away...

  1> String(Character(UnicodeScalar(65)))
$R1: String = "A"

Or (although I can't figure out why this one works) you can do

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