appendInterpolation(_:default:)
Interpolates the given optional value’s textual representation, or the specified default string, into the string literal being created.
Declaration
mutating func appendInterpolation<T>(_ value: T?, default: String) where T : CustomStringConvertible, T : TextOutputStreamableParameters
- value:
The value to include in a string interpolation, if non-
nil. - default:
The string to include if
valueisnil.
Discussion
You don’t need to call this method directly. It’s used by the compiler when interpreting string interpolations where you provide a default parameter. For example, the following code implicitly calls this method, using the value of the default parameter when value is nil:
var age: Int? = 48
print("Your age is \(age, default: "unknown")")
// Prints: Your age is 48
age = nil
print("Your age is \(age, default: "unknown")")
// Prints: Your age is unknown