0

I am trying to decode an emoji string saved in the SQL database as Amazing \ud83d\udc4c. I encode the emoji string with UTF8 String and then save it to the SQL database. However, when I try to decode the UTF 8 String, it always crash.

It crashed on the line when I try to convert the string using NSUTF8StringEncoding. If I try to print the string, it prints out a lot of garbage data which I am not able to understand, but it does not include the string.

Code I have tried for decode:

let commentString: String = commentArr[indexPath.row].valueForKey("comment") as! String 
let emojiData = commentString.dataUsingEncoding(NSUTF8StringEncoding)!
let emojiString = String(data: emojiData, encoding: NSNonLossyASCIIStringEncoding)

I would appreciate the help.

  • And if that does not work, please provide a concrete example of input, expected output and actual output. – Martin R Jul 06 '17 at 06:53
  • 1
    @MartinR I'm going to hammer with your suggestion. If the issue is different, the OP can ping me and I'll reopen the question. – JAL Jul 06 '17 at 13:13

0 Answers0