init(_:)
Creates a Unicode scalar with the specified numeric value.
Declaration
init?(_ v: Int)Parameters
- v:
The Unicode code point to use for the scalar.
vmust be a valid Unicode scalar value, in the ranges0...0xD7FFor0xE000...0x10FFFF. In case of an invalid unicode scalar value, nil is returned.
Discussion
For example, the following code sample creates a Unicode.Scalar instance with a value of an emoji character:
let codepoint = 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
}