Basic String Interpolation
Embed values directly inside string literals.
What Is String Interpolation
String interpolation builds a string by embedding values directly inside a string literal. You write a backslash followed by the value in parentheses, and Swift inserts its textual form.
let name = "Alice"
let greeting = "Hello, \(name)!"
print(greeting)Embedding a Number
Any value, not just strings, can be interpolated. Swift converts it to text automatically.
let age = 30
print("You are \(age) years old.")All lessons in this course
- Basic String Interpolation
- Formatting Numbers in Strings
- Multiline String Literals
- Custom String Interpolation