yesman82 yesman82 - 1 month ago 7
Swift Question

Print unicode character from variable (swift)

I have a problem I couldn't find a solution to.
I have a string variable holding the unicode "1f44d" and I want to convert it to a unicode character

Answer

This can be done in two steps:

  1. convert charAsString to Int code
  2. convert code to unicode character

Second step can be done e.g. like this

var code = 0x1f44d
var scalar = UnicodeScalar(code)
var string = "\(scalar)"

As for first the step, see here how to convert String in hex representation to Int

Comments