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 Interpolation

String interpolation

When i do the activity after the string interpolation explanation I get it wrong in your box, but it works fine in xcode, what am I doing wrong? Heres the code

let name = "Caitríona"
let finalGreeting = "\("Hi there"), \(name). \("How are you?")"

3 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Ciarian,

When doing string interpolation, you only need to interpolate things that aren't strings already, like constants, calculations, etc. You just need to remove some of your interpolation syntax:

let name = "Caitríona"
let finalGreeting = "Hi there, \(name). How are you?"

While the code you'd written does actually output the right string, this is the correct way to do it, since there's no need to string interpolate a string :smile:.

thanks, very helpful!

Anthia Tillbury
Anthia Tillbury
3,388 Points

That's what I was doing as well.

The demo video didn't show that natural language could be used, it gave the impression that everything had to be entered as string interpolated (encased in brackets with a back slash).