Working with Text
7 min · Swift
Join strings, measure them, and use string interpolation.
Enemy 1 of 5
This joins two strings with + and prints the result as one sentence. The pieces are "Hello, " and "Ada". Press Run to see them combined.
Why this works
Text in Swift is stored as a String value, written between double quotes. You can join two strings together with +, the same operator you use for adding numbers: Swift recognizes that + between two String values means "join them together" rather than "add them numerically."
Using + repeatedly works fine for joining two or three pieces, but it gets awkward once you're weaving several values (some text, a name, a number, more text) into a single sentence. That's precisely the problem the next section, string interpolation, is designed to solve more elegantly.
Rena
Your AI tutor. She walks you through each step.
Asking for help is part of coding. Rena reads your code and gives you a hint. She is free with an account: 20 hints a day.