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

Aditya Gawade
Aditya Gawade
1,182 Points

can't get interpolation of "Hi there," and the constant "name".

can't get interpolation of "Hi there," and the constant "name".

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

1 Answer

Ben Shockley
Ben Shockley
6,094 Points

In your greeting constant you have Hi there wrapped with a (). When you wrap something with () it tells the complier to interpolate whatever is inside there, or pull the value out of whatever it is referencing, essentially. Hi there can't be interpolated because it isn't referencing anything, the complier doesn't know what that is. What you want to do is just put your string "Hi there" and then an object to interpolate. So it would need to look like this.

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

Does this make sense?

Aditya Gawade
Aditya Gawade
1,182 Points

nice explanation. thanks a lot buddy