struct
StaticString
Initializers
Creates an empty static string.
Declaration
init
()
Creates an instance initialized to a single character that is made up of one or more Unicode code points.
Do not call this initializer directly. It may be used by the compiler when you initialize a static string using an extended grapheme cluster.
Declaration
init
(
extendedGraphemeClusterLiteral
value
:
StaticString
)
Creates an instance initialized to the value of a string literal.
Do not call this initializer directly. It may be used by the compiler when you initialize a static string using a string literal.
Declaration
init
(
stringLiteral
value
:
StaticString
)
Creates an instance initialized to a single Unicode scalar.
Do not call this initializer directly. It may be used by the compiler when you initialize a static string with a Unicode scalar.
Declaration
init
(
unicodeScalarLiteral
value
:
StaticString
)
Instance Variables
The custom mirror for this instance.
If this type has value semantics, the mirror should be unaffected by subsequent mutations of the instance.
Declaration
var
customMirror
:
Mirror
{
get
}
A textual representation of the static string, suitable for debugging.
Declaration
var
debugDescription
:
String
{
get
}
A Boolean value indicating whether the static string stores a pointer to ASCII or UTF-8 code units.
Declaration
var
hasPointerRepresentation
:
Bool
{
get
}
A Boolean value that is true
if the static string stores a pointer to
ASCII code units.
Use this property in conjunction with hasPointerRepresentation
to
determine whether a static string with pointer representation stores an
ASCII or UTF-8 code unit sequence.
Warning: If the static string stores a single Unicode scalar value, the
value of isASCII
is unspecified.
Declaration
var
isASCII
:
Bool
{
get
}
The stored Unicode scalar value.
The static string must store a single Unicode scalar value. Accessing
this property when hasPointerRepresentation
is true
triggers a
runtime error.
Declaration
var
unicodeScalar
:
UnicodeScalar
{
get
}
The length in bytes of the static string's ASCII or UTF-8 representation.
Warning: If the static string stores a single Unicode scalar value, the
value of utf8CodeUnitCount
is unspecified.
Declaration
var
utf8CodeUnitCount
:
Int
{
get
}
A pointer to the beginning of the string's UTF-8 encoded representation.
The static string must store a pointer to either ASCII or UTF-8 code
units. Accessing this property when hasPointerRepresentation
is
false
triggers a runtime error.
Declaration
var
utf8Start
:
UnsafePointer
<
UInt8
>
{
get
}
Instance Methods
Invokes the given closure with a buffer containing the static string's UTF-8 code unit sequence.
This method works regardless of whether the static string stores a pointer or a single Unicode scalar value.
body
: A closure that takes a buffer pointer to the static
string's UTF-8 code unit sequence as its sole argument. If the closure
has a return value, it is used as the return value of the
withUTF8Buffer(invoke:)
method.
Returns: The return value of the body
closure, if any.
Declaration
func
withUTF8Buffer
<
R
>
(
_
body
: (
UnsafeBufferPointer
<
UInt8
>
) -
>
R
) -
>
R
A string type designed to represent text that is known at compile time.
Instances of the
StaticString
type are immutable.StaticString
provides limited, pointer-based access to its contents, unlike Swift's more commonly usedString
type. A static string can store its value as a pointer to an ASCII code unit sequence, as a pointer to a UTF-8 code unit sequence, or as a single Unicode scalar value.