I have an API that will return a String with Unicode inside of it, for example:
Whether you think you can or whether you think you can't
–
you are right.
In the string above, –
is -
.
Currently, I'm using replacingOccurrences(of: "–", with: "\"", options: .regularExpression, range: nil)
to replace any Unicode inside the returned String. But once in a while I would get a Unicode that I didn't include in my list.
At the end of each returned String, I would use +
to combine the string with the Author of the Quote. When I use UnicodeScalar
to cast the String, Xcode would give me binary operator + cannot be applied to operands of type unicode and string
error.
I feel that my solution works, but it's not ideal. Is there a way to cast any Unicode with the returned String?