Swift version: 5.6
String interpolation is Swift's way of letting you insert variables and constants into strings. But at the same time, you can also perform simple operations as part of your interpolation, such as changing letter case and basic mathematics. Swift is also smart enough to understand how to bring values into strings, meaning that you can use other strings, integers and floating-point numbers just fine.
Here's an example to get you started:
let name = "Paul" let age = 35 let longestPi = 3.141592654 let combined = "This person's name is \(name.uppercased()), their age is \(age) so in \(age) years time they'll be \(age + age), and they know π up to \(longestPi)"
SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Available from iOS 7.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.