Initializer

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 v is a valid Unicode scalar value, in the range 0...0xD7FF or 0xE000...0x10FFFF. If v is an invalid unicode scalar value, the result is nil.

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
}

See Also

Creating a Scalar

init(UInt8)

Creates a Unicode scalar with the specified numeric value.

init(Unicode.Scalar)

Creates a duplicate of the given Unicode scalar.

init?(UInt32)

Creates a Unicode scalar with the specified numeric value.

init?(Int)

Creates a Unicode scalar with the specified numeric value.

init(unicodeScalarLiteral: Unicode.Scalar)

Creates a Unicode scalar with the specified value.

init?(String)

Instantiates an instance of the conforming type from a string representation.