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

I thought I had the right format, but I'm not sure if I misinterpreted the question. Can someone clarify?

Can't seem to code it correctly. Thanks in advance!

strings.swift
// Enter your code below

let named = "Frank"

let greeting = "Hi there"

let interpolatedGreeting = "\(greeting), \(named)"

2 Answers

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Francisco,

when I see your code I guess you're in the first task, right? If so, there are a few problems in your code, but you were on the right track! Firstly take care that you name your constants like the challenge asks you in the description, so please change the constant named to name. After that you should save the greeting in the constant greeting and also interpolate your name there and not in a separate constant.

To do that you can write it like that:

// Enter your code below

let name = "Frank"

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

Also note that you need a period in the end so please don't forget it. I hope that helps, good luck! :)

thanks so much for the clarification. When I eventually checked on Xcode the code below got me the same result as what you have above. Is it wrong to format it like this or was it mainly because the objective above wanted it in a specific way? Thanks again!

let name = "Frank"

let greeting = "Hi there"

let interpolatedGreeting = "(greeting), (name)"

Tobias Helmrich
Tobias Helmrich
31,603 Points

No problem, glad I could help! Yes, your code is absolutely fine! :)

However in the challenges it's always important to take care of the variable/constant names as they will be checked when your solution to the challenge is evaluated, besides that it's also important to look at small details like the period after the sentence for example which you don't have in your code.

I think the biggest problem in your code was that you made a separate variable and when the solution was evaluated it only looked for the greeting constant as this was the constant the challenge wants you to interpolate in and it could only find "Hi there" instead of the whole string with the interpolated constant.

But I know that it's sometimes difficult to take care of such small details and that it can be frustrating when your code is actually correct and working but you still don't pass the challenge. :)

Piotr Kuniniec
Piotr Kuniniec
10,723 Points

Hi, I think that u have to do add name to greeting:

let name = "Piotr" let greeting = "Hi there, (name)”

like that ;)