Convert Unicode (E.G. 1F564) to Emoji in Swift

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

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

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

Swift 3 convert unicode string U+1F600

Thanks vacawama and Edmar, both helped me find the solution which was as follows:

if let unicode = definition["unicode"] as? String {
if let int = Int(unicode.replacingOccurrences(of: "U+", with: ""), radix: 16) {
if let scalar = UnicodeScalar(int) {
let string = String(scalar)
emoji.text = string
}
}
}

Print unicode character from variable (swift)

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

Unicode String Interpolation

I tried poking around the internet and couldn't really find anything. You could parse the hex value out, and use that to make a UnicodeScalar, but I can't think of any nicer ways.

Swift String literal for unicode character is wrong

To represent the character in Swift you must use this kind of interpolation:

let dagger = "\u{2020}"

What Unicode characters represent time?

The following code points exist related to clocks, watches, and other devices to indicate time:

⌚  U+0231A  WATCH
⌛ U+0231B HOURGLASS
⏰ U+023F0 ALARM CLOCK
⏱ U+023F1 STOPWATCH
⏲ U+023F2 TIMER CLOCK
⏳ U+023F3 HOURGLASS WITH FLOWING SAND
⧖ U+029D6 WHITE HOURGLASS
⧗ U+029D7 BLACK HOURGLASS
U+1F4C5 CALENDAR
U+1F4C6 TEAR-OFF CALENDAR
U+1F550 CLOCK FACE ONE OCLOCK
U+1F55C CLOCK FACE ONE-THIRTY
U+1F551 CLOCK FACE TWO OCLOCK
U+1F55D CLOCK FACE TWO-THIRTY
U+1F552 CLOCK FACE THREE OCLOCK
U+1F55E CLOCK FACE THREE-THIRTY
U+1F553 CLOCK FACE FOUR OCLOCK
U+1F55F CLOCK FACE FOUR-THIRTY
U+1F554 CLOCK FACE FIVE OCLOCK
U+1F560 CLOCK FACE FIVE-THIRTY
U+1F555 CLOCK FACE SIX OCLOCK
U+1F561 CLOCK FACE SIX-THIRTY
U+1F556 CLOCK FACE SEVEN OCLOCK
U+1F562 CLOCK FACE SEVEN-THIRTY
U+1F557 CLOCK FACE EIGHT OCLOCK
U+1F563 CLOCK FACE EIGHT-THIRTY
U+1F558 CLOCK FACE NINE OCLOCK
U+1F564 CLOCK FACE NINE-THIRTY
U+1F559 CLOCK FACE TEN OCLOCK
U+1F565 CLOCK FACE TEN-THIRTY
U+1F55A CLOCK FACE ELEVEN OCLOCK
U+1F566 CLOCK FACE ELEVEN-THIRTY
U+1F55B CLOCK FACE TWELVE OCLOCK
U+1F567 CLOCK FACE TWELVE-THIRTY
U+1F570 MANTELPIECE CLOCK
U+1F5D3 SPIRAL CALENDAR PAD

You can copy and paste the characters from this page into most editors.

At unicode-table.com you might find more useful code points.



Related Topics



Leave a reply



Submit