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

James Louw
James Louw
10,105 Points

Code works in Xcode but not on the website

Hi, I am currently in the beginning of my Swift coding course and I have a slight problem.

The code I have entered below displays the correct answer when it is in XCode (it displays "Hi there, James.") but when I enter it on the website it says it is incorrect.

Any help will be much appreciated.

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

1 Answer

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey James,

you just have to interpolate variables or constants inside of a String but you're trying to interpolate the String itself by writing it inside of \() . You can just write the String and inside of it you can interpolate the constant name.

Like so:

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

I hope that helps, if you have further questions feel free to ask! :)

James Louw
James Louw
10,105 Points

Thank you for the help, works perfectly :)