The following example is taken from the Strings and Characters documentation:
The values 55357
(U+D83D
in hex) and 56374
(U+DC36
in hex) are the surrogate pairs that form the Unicode scalar U+1F436
, which is the DOG FACE
character. Is there any way to go the other direction? That is, can I convert a surrogate pair into a scalar?
I tried
let myChar: Character = "\u{D83D}\u{DC36}"
but I got an "Invalid Unicode scalar" error.
This Objective C answer and this project seem to be custom solutions, but is there anything built into Swift (especially Swift 2.0+) that does this?