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 trialBrian Goodwin
455 Pointsin 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
42,016 Pointsinterpolation 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
eugeneteo
112 PointsYou can omit the "+" in "var greeting = \(str) +\(language)."
Brian Goodwin
455 PointsBrian Goodwin
455 PointsThanks Stone. I think that make sense, rather than having to manage the syntax of all the different symbols and punctuation, you can use interpolation.
Brian Goodwin
455 PointsBrian Goodwin
455 PointsThanks 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
42,016 PointsStone Preston
42,016 Pointsalso note that interpolation uses \, not /
"interpolating a value \(someVariable)"