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

Valeria Ruiz
Valeria Ruiz
948 Points

concatenation mistake or bug?

I am doing Swift 2.0 Basics and I am learning about concatenation. I have tried everything I have learned so far for this method and still I can't get it right. The error message I get ays to make sure I am using concatenation, which I am.

Could someone please help me in finding out how I could concatenate better? My code is below

// Enter your code below
let name = "Valeria"
let hi = "Hi"
let there = "there"
let greeting = "\(hi) \(there), \(name)."
let stringLiteral = "How are you?"
let finalGreeting = "\(greeting) \(stringLiteral)"

2 Answers

Hi Valeria,

Concatention is adding the strings together using the plus sign. What you've done there is interpolation.

So, finalGreeting should be made up of greeting + " How are you".

Something like this should get you through the challenge:

// Enter your code below
let name = "Steve"
let greeting = "Hi there, \(name)"
let finalGreeting = greeting + " How are you?"

You start with name holding your name, then interpolate that into the greeting constant. Next, you concatenate greeting with the additional string " How are you?" by adding them together using the + operator.

I hope that helps,


Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

Beat me on that ;) One thing worth mentioning is that, just like in Steves solution, you really only have to wrap dynamic parts (like variables) of the string in \() when using string interpolation. All static parts are just like regular strings. See Apple docs.


Valeria Ruiz
Valeria Ruiz
948 Points

thanks so much guys!

No problem! :smile: