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

PLEASE HELP ME WITH STRING INTERPOLATION!!! Why is this wrong?

please

strings.swift
// Enter your code below
let name = "Andrea"
let greeting = "Hi there, \(name) \."
Ghaith Ali
Ghaith Ali
3,134 Points

i think you have a problem with the syntax of String interpolation, this is how i would do it:

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

I think your problem is that you are adding the extra back slash at the end, that causes the compiler to expect a function. hope my answered helps

1 Answer

You added an extra \ to your string. Think of String Interpolation as a placeholder for your parameter, variable, constant, etc.

So for you:

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

or another example:

var petThatILove = "cats"
let sentenceIUseOftenOnTheInternet = "I love \(petThatILove)."

which if printed (print()) would say "I love cats."