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 2.0 Basics Swift Types String Manipulation

interpolated strings

not working

strings.swift
// Enter your code below
let name = "Matthew."
let greeting = "Hi there"
let interpolated address = greeting+"," +name

2 Answers

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Amaury,

the problem in your code is that you're trying to interpolate the string itself here:

\(Hi there)

"Hi there" is no variable (and wouldn't be a valid name for one), so you don't have to interpolate it and you can just write the string. Also note that even though it works like this it would be better and cleaner code when you write the period in the greeting instead of in your name constant like so:

let name = "Christian"
let greeting = "Hi there, \(name)."

I hope you understand what was wrong in your code now and that I could help you, good luck! :)

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Matthew,

there are a few things wrong in your code. You're using string concatenation instead of interpolation, to interpolate a variable or constant in a string you have to write the variable/constant inside of \() . Also note that you can't write spaces between words in a constant/variable name like you did in "interpolated address".

So if you're interpolating your name in the greeting constant you do it like that:

// Enter your code below
let name = "Matthew"
let greeting = "Hi there, \(name)."

I hope that helps! :)

Christian A. Castro
Christian A. Castro
30,501 Points

I was writing:

let name = "Christian."
let greeting = "\(Hi there), \(name)"

which it was wrong.

Thank you, Tobias Helmrich !!! Amaury.

thanks