0

so I'm trying to convert a unicode string U+1F600 coming from json into a UILabel but having a hell of a time.

Has anybody encountered this? It also seems JSON coming in as \u1f600 has the same issues.

I've tried this method with no luck: Emoji characters cannot be encoded to JSON

Thanks so much

Community
  • 1
  • 1
cYberSport91
  • 183
  • 8

2 Answers2

1

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
        }
    }
}
cYberSport91
  • 183
  • 8
0

In your JSON response, does \u1f600 comes in a string format ? If so, try this:

let transform = "Any-Hex/Java"
let input = "\\u1f600" as NSString
var output = input.mutableCopy() as NSMutableString

CFStringTransform(output, nil, transform as NSString, 1)

println("output: \(output)")
Edmar Miyake
  • 12,047
  • 3
  • 37
  • 38