init(_:)
Creates a Unicode scalar with the specified numeric value.
Declaration
init?(_ v: UInt32)Parameters
- v:
The Unicode code point to use for the scalar. The initializer succeeds if
vis a valid Unicode scalar value—that is, ifvis 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 an emoji character:
let codepoint: UInt32 = 127881
let emoji = Unicode.Scalar(codepoint)
print(emoji!)
// Prints "🎉"In case of an invalid input value, nil is returned.
let codepoint: UInt32 = extValue // This might be an invalid value
if let emoji = Unicode.Scalar(codepoint) {
print(emoji)
} else {
// Do something else
}