init(_:)
Creates a Unicode scalar with the specified numeric value.
Declaration
init?(_ v: UInt16)Parameters
- v:
The Unicode code point to use for the scalar. The initializer succeeds if
vis a valid Unicode scalar value, in the range0...0xD7FFor0xE000...0x10FFFF. Ifvis an invalid unicode scalar value, the result isnil.
Discussion
For example, the following code sample creates a Unicode.Scalar instance with a value of "밥", the Korean word for rice:
let codepoint: UInt16 = 48165
let bap = Unicode.Scalar(codepoint)
print(bap!)
// Prints "밥"In case of an invalid input value, the result is nil.
let codepoint: UInt16 = extValue // This might be an invalid value
if let bap = Unicode.Scalar(codepoint) {
print(bap)
} else {
// Do something else
}