<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/DefaultStringInterpolation",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s26DefaultStringInterpolationV"
  },
  "title" : "DefaultStringInterpolation"
}
-->

# DefaultStringInterpolation

Represents a string literal with interpolations while it’s being built up.

```
@frozen struct DefaultStringInterpolation
```

## Overview

You don’t need to create an instance of this type directly. It’s used by the
compiler when you create a string using string interpolation. Instead, use
string interpolation to create a new string by including values, literals,
variables, or expressions enclosed in parentheses, prefixed by a
backslash (`\(`…`)`).

```
let price = 2
let number = 3
let message = """
              If one cookie costs \(price) dollars, \
              \(number) cookies cost \(price * number) dollars.
              """
print(message)
// Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
```

When implementing an `ExpressibleByStringInterpolation` conformance,
set the `StringInterpolation` associated type to
`DefaultStringInterpolation` to get the same interpolation behavior as
Swift’s built-in `String` type and construct a `String` with the results.
If you don’t want the default behavior or don’t want to construct a
`String`, use a custom type conforming to `StringInterpolationProtocol`
instead.

# Extending default string interpolation behavior

Code outside the standard library can extend string interpolation on
`String` and many other common types by extending
`DefaultStringInterpolation` and adding an `appendInterpolation(...)`
method. For example:

```
extension DefaultStringInterpolation {
    fileprivate mutating func appendInterpolation(
             escaped value: String, asASCII forceASCII: Bool = false) {
        for char in value.unicodeScalars {
            appendInterpolation(char.escaped(asASCII: forceASCII))
        }
    }
}

print("Escaped string: \(escaped: string)")
```

See `StringInterpolationProtocol` for details on `appendInterpolation`
methods.

`DefaultStringInterpolation` extensions should add only `mutating` members
and should not copy `self` or capture it in an escaping closure.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)