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.