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 trialBruno Melo
729 PointsString interpolation
I have to interpolate two Strings: First create a constant name and assign my name; Second declare the constant greeting using interpolation, and the result must be: "Hi there, Bruno." What I'm doing is: var name = "Bruno." var greeting = "(Hi there), (name)"
But the error above keeps showing
1 Answer
Nathan Tallack
22,160 PointsFirst of all, remember a constant is declared with let not var. Only use var if you are going to change the value later.
Next, when we want to insert a value into a string (interpolation) we use () to do it. The \ escapes the ( so that Swift knows you are going to put a value inside the brackets.
So the code would look something like this.
let name = "John"
let greeting = "Hi there, \(name)."
Hope this helps. :)