---
title: StaticString
framework: swift
role: symbol
role_heading: Structure
path: swift/staticstring
---

# StaticString

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

## Declaration

```swift
@frozen struct StaticString
```

## Overview

Overview Instances of the StaticString type are immutable. StaticString provides only low-level access to its contents, unlike Swift’s more commonly used String type. A static string can use either of the following as its storage: a pointer to a null-terminated sequence of UTF-8 code units: let emoji: StaticString = "\u{1F600}" emoji.hasPointerRepresentation  //-> true emoji.isASCII                   //-> false emoji.unicodeScalar             //-> Fatal error! emoji.utf8CodeUnitCount         //-> 4 emoji.utf8Start[0]              //-> 0xF0 emoji.utf8Start[1]              //-> 0x9F emoji.utf8Start[2]              //-> 0x98 emoji.utf8Start[3]              //-> 0x80 emoji.utf8Start[4]              //-> 0x00 a single Unicode scalar value, under very limited circumstances: struct MyStaticScalar: ExpressibleByUnicodeScalarLiteral {     typealias UnicodeScalarLiteralType = StaticString     let value: StaticString     init(unicodeScalarLiteral value: StaticString) {         self.value = value     } }

let emoji: StaticString = MyStaticScalar("\u{1F600}").value emoji.hasPointerRepresentation  //-> false emoji.isASCII                   //-> false emoji.unicodeScalar.value       //-> 0x1F600 emoji.utf8CodeUnitCount         //-> Fatal error! emoji.utf8Start                 //-> Fatal error! You can use the withUTF8Buffer(_:) method to access a static string’s contents, regardless of which representation the static string uses. emoji.withUTF8Buffer { utf8 in     utf8.count  //-> 4     utf8[0]     //-> 0xF0     utf8[1]     //-> 0x9F     utf8[2]     //-> 0x98     utf8[3]     //-> 0x80     utf8[4]     //-> Fatal error! }

## Topics

### Initializers

- [init()](swift/staticstring/init().md)

### Instance Properties

- [hasPointerRepresentation](swift/staticstring/haspointerrepresentation.md)
- [isASCII](swift/staticstring/isascii.md)
- [unicodeScalar](swift/staticstring/unicodescalar.md)
- [utf8CodeUnitCount](swift/staticstring/utf8codeunitcount.md)
- [utf8Start](swift/staticstring/utf8start.md)

### Instance Methods

- [withUTF8Buffer(_:)](swift/staticstring/withutf8buffer(_:).md)

### Default Implementations

- [CustomDebugStringConvertible Implementations](swift/staticstring/customdebugstringconvertible-implementations.md)
- [CustomReflectable Implementations](swift/staticstring/customreflectable-implementations.md)
- [CustomStringConvertible Implementations](swift/staticstring/customstringconvertible-implementations.md)
- [ExpressibleByExtendedGraphemeClusterLiteral Implementations](swift/staticstring/expressiblebyextendedgraphemeclusterliteral-implementations.md)
- [ExpressibleByStringLiteral Implementations](swift/staticstring/expressiblebystringliteral-implementations.md)
- [ExpressibleByUnicodeScalarLiteral Implementations](swift/staticstring/expressiblebyunicodescalarliteral-implementations.md)

## Relationships

### Conforms To

- [BitwiseCopyable](swift/bitwisecopyable.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Escapable](swift/escapable.md)
- [ExpressibleByExtendedGraphemeClusterLiteral](swift/expressiblebyextendedgraphemeclusterliteral.md)
- [ExpressibleByStringLiteral](swift/expressiblebystringliteral.md)
- [ExpressibleByUnicodeScalarLiteral](swift/expressiblebyunicodescalarliteral.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
