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

larry bland
PLUS
larry bland
Courses Plus Student 7,846 Points

ok i thought i had it

is my code off

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

3 Answers

Ollie King
Ollie King
10,194 Points

Hi Larry,

As you are using string interpolation, you don't need to add the binding operator (+). Try removing the '+' in your code and this should solve the problem :)

larry bland
PLUS
larry bland
Courses Plus Student 7,846 Points

interesting but the code challenge suggests that i am not using interpolation

Ollie King
Ollie King
10,194 Points

Ah ok, in that situation as when concatenating a string then the code would look like this:

// Enter your code below

let name = "Larry" let greeting = "Hi there, (name)." // Interpolation

let finalGreeting = greeting + "How are you?" // Concatenation

the backslash and parenthesis only apply in interpolation.

So reviewing your code above you were really close!

Your second line of code didn't require the binary operator between "Hi there, " and (name) Then your third line of code didn't need the backslash and parenthesis and only "double quotes" around "How are you?"

Does this help? Or have I just confused you further..? Haha! :)

larry bland
PLUS
larry bland
Courses Plus Student 7,846 Points

lol a little so with interpolation once the variable is declared with interpolation there is no need to redeclare with the ()

Ollie King
Ollie King
10,194 Points

Haha no problem. I'll try my best to explain.

It depends if you are going to use interpolation or concatenation in the new variable/constant. Basically all your doing is creating variables/constants and using them together in a string.

If you were to do this solely using interpolation then the variables/constants you are referencing go into () as you are directly pulling them into you "String of text", otherwise it would all read as a string rather than a string with added values (e.g. "Hi there, (name)" without the () would literally print "Hi there, name" rather than the desired "Hi there, Larry").

If you were to do this solely using concatenation then the referenced variables/constants don't require anything but you need to add the binary operator. You're essentially saying grab greeting /which is already holding data "Hi there, (name)"/. and add(+) "How are you?" - How are you has to be in double quotes as this is a string.