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 scalar values.
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
:
Unicode.Scalar
{
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.
The pointer argument to body
is valid only during the execution of
withUTF8Buffer(_:)
. Do not store or return the pointer for later use.
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, that value is also used as the return value of the
withUTF8Buffer(invoke:)
method. The pointer argument is valid only
for the duration of the method's execution.
Returns: The return value, if any, of the body
closure.
Declaration
func
withUTF8Buffer
<
R
>
(
_
body
: (
UnsafeBufferPointer
<
UInt8
>
) -
>
R
) -
>
R
Conditionally Inherited Items
The initializers, methods, and properties listed below may be available on this type under certain conditions (such as methods that are available on Array
when its elements are Equatable
) or may not ever be available if that determination is beyond SwiftDoc.org's capabilities. Please open an issue on GitHub if you see something out of place!
Where ExtendedGraphemeClusterLiteralType == StringLiteralType
Creates an instance initialized to the given value.
value
: The value of the new instance.
Declaration
init
(
extendedGraphemeClusterLiteral
value
:
StaticString
.
StringLiteralType
)
Declared In
ExpressibleByStringLiteral
1 inherited item hidden. (Show all)
Where ExtendedGraphemeClusterLiteralType == UnicodeScalarLiteralType
Creates an instance initialized to the given value.
value
: The value of the new instance.
Declaration
init
(
unicodeScalarLiteral
value
:
StaticString
.
ExtendedGraphemeClusterLiteralType
)
Declared In
ExpressibleByStringLiteral
, ExpressibleByExtendedGraphemeClusterLiteral
1 inherited item hidden. (Show all)
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.