0

How can I convert this type of hex string

🚗

to emoji, and vice versa?

I have tried to use this, but its returns same string

func decode(_ s: String) -> String? {
    let data = s.data(using: .utf8)!
    return String(data: data, encoding: .nonLossyASCII)
}
rmaddy
  • 307,833
  • 40
  • 508
  • 550
Narek Simonyan
  • 550
  • 1
  • 7
  • 18

1 Answers1

0

(I am force unwrapping for the sake of simplicity, since the specified emoji hex is valid)

let hexStr = String("🚗".dropFirst(3).dropLast())
let emoji = String(UnicodeScalar(Int(hexStr, radix: 16)!)!)
stakri
  • 1,309
  • 1
  • 11
  • 14
  • thanks, and what about this type of hex "⌛️" there are emojis which are combine of multiple emojis, how should I use it? – Narek Simonyan Nov 07 '17 at 21:06