Structure

StaticString

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

Overview

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.

Topics

Initializers

init()

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 code points.

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 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)

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