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 Swift Basics (retired) Types Printing Results

in reference to this video- what is the difference between using string interpolation /(str) and simply using str +

var str = "Hello "

let language = "Swift"

var greeting = str + language

or

var str = "Hello "

let language = "Swift"

var greeting = /(str) +/(language)

2 Answers

Stone Preston
Stone Preston
42,016 Points

interpolation makes it easier to "build strings" using values of variables and constants in your code.

you can do the same thing using string concatenation, however then you have to manage all your plus signs, spaces, quotation marks etc. Interpolation just makes things much much easier and I find myself using interpolation pretty much all the time

Thanks Stone. I think that make sense, rather than having to manage the syntax of all the different symbols and punctuation, you can use interpolation.

Thanks Stone. I think that make sense, rather than having to manage the syntax of all the different symbols and punctuation, you can use interpolation.

Stone Preston
Stone Preston
42,016 Points

also note that interpolation uses \, not /

"interpolating a value \(someVariable)"

You can omit the "+" in "var greeting = \(str) +\(language)."