A string type designed to represent text that is known at compile time.


@frozen struct StaticString


Instances of the StaticString type are immutable. StaticString provides limited, pointer-based access to its contents, unlike Swift’s more commonly used String 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.


Type Aliases

typealias StaticString.ExtendedGraphemeClusterLiteralType

A type that represents an extended grapheme cluster literal.

typealias StaticString.StringLiteralType

A type that represents a string literal.

typealias StaticString.UnicodeScalarLiteralType

A type that represents a Unicode scalar literal.




Creates an empty static string.

init(extendedGraphemeClusterLiteral: StaticString)

Creates an instance initialized to a single character that is made up of one or more Unicode scalar values.

init(stringLiteral: StaticString)

Creates an instance initialized to the value of a string literal.

init(unicodeScalarLiteral: StaticString)

Creates an instance initialized to a single Unicode scalar.

Instance Properties

var customMirror: Mirror

The custom mirror for this instance.

var debugDescription: String

A textual representation of the static string, suitable for debugging.

var description: String

A string representation of the static string.

var hasPointerRepresentation: Bool

A Boolean value indicating whether the static string stores a pointer to ASCII or UTF-8 code units.

var isASCII: Bool

A Boolean value that is true if the static string stores a pointer to ASCII code units.

var unicodeScalar: Unicode.Scalar

The stored Unicode scalar value.

var utf8CodeUnitCount: Int

The length in bytes of the static string’s ASCII or UTF-8 representation.

var utf8Start: UnsafePointer<UInt8>

A pointer to the beginning of the string’s UTF-8 encoded representation.

Instance Methods

func withUTF8Buffer<R>((UnsafeBufferPointer<UInt8>) -> R) -> R

Invokes the given closure with a buffer containing the static string’s UTF-8 code unit sequence.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software