Convert emoji to hex value using Swift
问题 I'm trying to convert emojis in hex values, I found some code online to do it but it's only working using Objective C, how to do the same with Swift? 回答1: This is a "pure Swift" method, without using Foundation: let smiley = "😊" let uni = smiley.unicodeScalars // Unicode scalar values of the string let unicode = uni[uni.startIndex].value // First element as an UInt32 print(String(unicode, radix: 16, uppercase: true)) // Output: 1F60A Note that a Swift Character represents a "Unicode grapheme