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

Bob Clanfield
Bob Clanfield
2,372 Points

On the second task: Being guided to interpolate then after I revise, told to concatenate. Both work in Xcode.

let name = "Bob" let greeting = "Hi there, " let finalGreeting = "(greeting + name). How are you?"

then I'll try

let name = "Bob" let greeting = "Hi there," + name let finalGreeting = "(greeting). How are you?"

strings.swift
// am I not using concatenation? 



let name = "Bob"
let greeting = "Hi there, "
let finalGreeting = "\(greeting + name).  How are you?"

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You are, but you are simultaneously using interpolation. You are interpolating the concatenation of the two. The value of greeting should hold "Hi there, Bob" using interpolation. The finalGreeting should contain the value of "Hi there, Bob. How are you?". This value should be obtained using only concatenation and not interpolation. That being said, you removed the interpolation from the first step that you did in Step 1.

Take a look:

let flavor = "lemon"
let favoriteFlavor = "chocolate"

// using only interpolation
let myCake = "I like \(flavor) cake. "

// using only concatenation
let favoriteCake = myCake + "But my favorite flavor is " + favoriteFlavor

Interpolation is when we use the backslash and parentheses to insert the value of a variable into a spot in a string. Concatenation is the combination of two strings with a + sign. In your code, as you can see, you did a combination, which works, but the challenge is specifically testing to see if you can get the same results using two different methods.

I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

Bob Clanfield
Bob Clanfield
2,372 Points

Hi Jennifer, First, Thank Ü for your reply! I think I understand what your suggesting and feel I've been able to apply it but it still comes back with "bummer"

let name = " Bob"

let greeting = "Hi there,"

let finalGreeting = greeting + name + ". How are you?"

I also tried let name = " Bob"

let greeting = "Hi there," + name

let finalGreeting = greeting + ". How are you?"

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again! We'll you're closer, but again, you removed the interpolation from line 2. You were not meant to change anything from Step 1.

Here was the line from Step 1 that is no longer correct in your code, but was at some point.

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

You were meant to use only interpolation in line 2 and only concatenation in line3.

These tasks are cumulative. The challenges even state that you should build upon the code from the previous step. Give it one more go! :sparkles:

Bob Clanfield
Bob Clanfield
2,372 Points

I did figure it out. Part of what was going on was that Task 2 is not a separate task, rather a continuation. After I figured it out My code was not combining with the previous I started over.

Once again Thank Ü you absolutely clarified what I was missing! After that it was semantics. ¯_(ツ)_/¯ ॐ

let name = " Bob"

let greeting = "Hi there (name)"

let finalGreeting = greeting + ". How are you?"