Scalar
A Unicode scalar value.
@frozen struct Scalar
The Unicode.Scalar
type, representing a single Unicode scalar value, is the element type of a string’s unicodeScalars
collection.
You can create a Unicode.Scalar
instance by using a string literal that contains a single character representing exactly one Unicode scalar value.
let letterK: Unicode.Scalar = "K"
let kim: Unicode.Scalar = "김"
print(letterK, kim)
// Prints "K 김"
You can also create Unicode scalar values directly from their numeric representation.
let airplane = Unicode.Scalar(9992)!
print(airplane)
// Prints "✈︎"
Citizens in Swift
Conformances
protocol Comparable
A type that can be compared using the relational operators
<
,<=
,>=
, and>
.protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol CustomReflectable
A type that explicitly supplies its own mirror.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol ExpressibleByUnicodeScalarLiteral
A type that can be initialized with a string literal containing a single Unicode scalar value.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol LosslessStringConvertible
A type that can be represented as a string in a lossless, unambiguous way.
protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.
protocol TextOutputStreamable
A source of text-streaming operations.
Members
init(Unicode
.Scalar) Creates a duplicate of the given Unicode scalar.
init?(String
) init?(Int
) Creates a Unicode scalar with the specified numeric value.
init?(UInt16
) Creates a Unicode scalar with the specified numeric value.
init?(UInt32
) Creates a Unicode scalar with the specified numeric value.
init(UInt8
) Creates a Unicode scalar with the specified numeric value.
init(unicodeScalarLiteral: Unicode.Scalar
) Creates a Unicode scalar with the specified value.
var customMirror: Mirror
A mirror that reflects the
Unicode.Scalar
instance.var debugDescription: String
An escaped textual representation of the Unicode scalar, suitable for debugging.
var description: String
A textual representation of the Unicode scalar.
var isASCII: Bool
A Boolean value indicating whether the Unicode scalar is an ASCII character.
var properties: Unicode.Scalar.Properties
Properties of this scalar defined by the Unicode standard.
var utf16: Unicode.Scalar.UTF16View
var utf8: Unicode.Scalar.UTF8View
var value: UInt32
A numeric representation of the Unicode scalar.
static func < (Unicode
.Scalar, Unicode.Scalar) -> Bool static func == (Unicode
.Scalar, Unicode.Scalar) -> Bool func escaped(asASCII: Bool
) -> String Returns a string representation of the Unicode scalar.
func hash(into: inout Hasher
) Hashes the essential components of this value by feeding them into the given hasher.
func write<Target>(to: inout Target
) Writes the textual representation of the Unicode scalar into the given output stream.
struct Properties
A value that provides access to properties of a Unicode scalar that are defined by the Unicode standard.
struct UTF16View
struct UTF8View
var customPlaygroundQuickLook: _PlaygroundQuickLook
A custom playground Quick Look for the
Unicode.Scalar
instance.
Features
static func != (Self, Self
) -> Bool static func ... (Self
) -> PartialRangeFrom<Self> Returns a partial range extending upward from a lower bound.
static func ... (Self
) -> PartialRangeThrough<Self> Returns a partial range up to, and including, its upper bound.
static func ... (Self, Self
) -> ClosedRange<Self> Returns a closed range that contains both of its bounds.
static func ..< (Self
) -> PartialRangeUpTo<Self> Returns a partial range up to, but not including, its upper bound.
static func ..< (Self, Self
) -> Range<Self> Returns a half-open range that contains its lower bound but not its upper bound.
Available in _RegexParser
Members
static var allScalars: Unicode.Scalar.AllScalars
var isPrintableASCII: Bool
Whether this character represents a printable ASCII character, for the purposes of pattern parsing.
struct AllScalars
Available in RegexBuilder
Conformances
protocol RegexComponent
A type that represents a regular expression.
Members
Extension in Grammar
Conformances
protocol ASCIITerminal
A terminal type that can match an ASCII pattern.
protocol UnicodeTerminal
A terminal type that can match a
Unicode.Scalar
pattern.
Extension in JSONDecoding
Conformances
protocol JSONDecodable
A type that can be decoded from a JSON variant value.
protocol JSONStringDecodable
A type that can be decoded from a JSON UTF-8 string. This protocol exists to allow types that also conform to
LosslessStringConvertible
to opt-in to automaticJSONDecodable
conformance as well.
Extension in JSONEncoding
Conformances
protocol JSONEncodable
A type that can be encoded to a JSON variant value.
Members
Extension in BSONDecoding
Conformances
protocol BSONDecodable
A type that can be decoded from a BSON variant value backed by some type of storage not particular to the decoded type.
protocol BSONStringDecodable
A type that can be decoded from a BSON UTF-8 string. Javascript sources count as UTF-8 strings, from the perspective of this protocol. This protocol exists to allow types that also conform to
LosslessStringConvertible
to opt-in to automaticBSONDecodable
conformance as well.
Extension in BSONEncoding
Conformances
protocol BSONEncodable
A type that can be encoded to a BSON variant value.
Members
Extension in SwiftParser
Members
static func lexing(from: some Collection<UInt8>
) -> Unicode.Scalar? Returns the first unicode scalar in
byteSequence
, which may span multiple bytes.
Extension in HTMLStreaming
Conformances
Members
Extension in JSONDecoding
Conformances
protocol JSONDecodable
A type that can be decoded from a JSON variant value.
protocol JSONStringDecodable
A type that can be decoded from a JSON UTF-8 string. This protocol exists to allow types that also conform to
LosslessStringConvertible
to opt-in to automaticJSONDecodable
conformance as well.
Extension in JSONEncoding
Conformances
protocol JSONEncodable
protocol JSONStringEncodable
A type that can be encoded to a JSON string. This protocol exists to allow types that also conform to
LosslessStringConvertible
to opt-in to automaticJSONEncodable
conformance as well.