All lessons

Working with Text

7 min · Swift

Join strings, measure them, and use string interpolation.

Swift · Working with Text0/5 cleared

Enemy 1 of 5

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.

You
Packet Wolf

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, Ada