user431791 user431791 - 20 days ago 8
iOS Question

How to convert special characters in dictionary to unicode in swift

//temporary dictionary
let tempDict = ["ttTasks":"€ is euro symbol"]


//conversion should replace € symbol with \u20ac

so final dictionary would be

finalDict = ["ttTasks":"\u20ac is euro symbol"]


NOTE: please do not suggest me
replaceOccurencesOfString
as i need to do this for every special character.

Answer

Something like this maybe:

for key in tempDict.keys {
    let data = tempDict[key]?.data(using: String.Encoding.nonLossyASCII)
    tempDict[key] = String(data: data!, encoding: String.Encoding.utf8)
}