I want to set the value of a constant UInt16
to a hexadecimal value.
I know that the way to set a Swift Character
is
let myValue: Character = "\u{1820}"
so I tried
let myValue: UInt16 = "\u{1820}"
let myValue: unichar = "\u{1820}"
let myValue: UInt16 = "\u{1820}".utf16
let myValue: unichar = "\u{1820}".utf16
let myValue = "\u{1820}"
but none of these worked.
When searching for the answer, I mostly got SO questions about converting from NSString
or other type.
This is surely a silly question for all you experienced Objective C programmers, but I was having a hard time finding the answer. I finally did find it, though, so I will share my question and answer to hopefully add a few keywords for others who may search for the same question in the future.
Note:
- How to initialize a unichar variable in swift? This Q&A doesn't tell how to initialize with hexadecimal.