Represents a string literal with interpolations while it is being built up.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
Overview
Do not create an instance of this type directly. It is 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 (\(
…)
).
When implementing an Expressible
conformance, set the String
associated type to Default
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 String
instead.
Extending default string interpolation behavior
Code outside the standard library can extend string interpolation on String
and many other common types by extending Default
and adding an append
method. For example:
See String
for details on append
methods.
Default
extensions should add only mutating
members and should not copy self
or capture it in an escaping closure.