Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Solution: Thinking About Types

Why don't I have to use the \() to interpolate?

In the Thinking About Types excercise within the Manipulating Data practice sessions there is code similar to the following:

var isReady = true isReady = false

let value = 10 let valueTimesThree = value * 3

let name = "Pasan" let lastName = "Premaratne"

In the second section, I would assume that in order to use the value constant within the valueTimesThree constant I would have had to write it like this, 'backslash'(value). Why don't I need to do this?

1 Answer

andren
andren
28,558 Points

The \() syntax is used to insert a variable within a string, it makes it clear to Swift that you are referencing a variable and not just typing normal text. Outside of strings that distinction is not needed, as Swift assumes that all words typed is either a keyword, variable or something similar.

That means that whenever you want to reference a variable outside a string you simply have to type its name, nothing more. This is true regardless of whether the variable is used in a math operation, passed to a function or pretty much anything else.