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

Utsah Kapoor
Utsah Kapoor
696 Points

I got the correct answer but its not saying its right

So I am in swift 2 basics and I have used the xcode playground and checked. It works but Im some how doing it wrong please help.

Here is my code

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

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi there,

you don't need to enclose the "hi there, " with \(), this notion is used for injecting variable variable into the String (String interpolation).

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

This would be suffice.

Utsah Kapoor
Utsah Kapoor
696 Points

Thanks, but when I answer the second question in this way I get an incorrect answer.

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

William Li
William Li
Courses Plus Student 26,868 Points

Yes, second part strictly required that you use String concatenation to combine two string together; that's you need to use the plus sign + to combine 2 strings into one.

// Enter your code below
let name = "Utsah"
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + " How are you?"  // String concatenation
Krzysztof Kucharzyk
seal-mask
.a{fill-rule:evenodd;}techdegree
Krzysztof Kucharzyk
Front End Web Development Techdegree Student 4,005 Points

In this task I guess you should try using interpolation instead of concatenation. Try with this code below:

let name = "Utsah"
let hello = "Hi there"
let greeting = "\(hello), \(name)."