Initializer

init(stringInterpolation:)

Creates a new string by concatenating the given interpolations.

Declaration

init(stringInterpolation strings: String...)

Discussion

Do not call this initializer 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 (\()).

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."

See Also

Infrequently Used Functionality

init<T>(stringInterpolationSegment: T)

Creates a string containing the given value’s textual representation.

init<T>(stringInterpolationSegment: T)

Creates a string containing the given value’s textual representation.

init<T>(stringInterpolationSegment: T)

Creates a string containing the given expression’s textual representation.

init<T>(stringInterpolationSegment: T)

Creates a string containing the given value’s textual representation.

init(stringLiteral: String)

Creates an instance initialized to the given string value.

init(unicodeScalarLiteral: String)

Creates an instance initialized to the given value.

init(extendedGraphemeClusterLiteral: String)

Creates an instance initialized to the given value.