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

Anna Benson
Anna Benson
2,728 Points

Am I incorrectly creating interpolated strings?

I thought I was correctly following the syntax for interpolated strings shown in the examples in the video, but I keep getting an error message pop up for this code challenge saying "Make sure the value for greeting is an interpolated string."

What is wrong with my code for the constant greeting?

strings.swift
// Enter your code below
let name = "Anna"

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

2 Answers

Nathan Tallack
Nathan Tallack
22,159 Points

Like this.

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

You write your string literally normally. That's the stuff between the "" quotes. Anytime you want to insert a value in there, like we did with the constant "name" above you pop the value inside of the () brackets. Because we want it to understand the bracket we escape the opening bracket with the \, otherwise it will think you just want to include the brackets in your string literal.

Hope this helps. :)

Anna Benson
Anna Benson
2,728 Points

Thank you so much! That was way simpler than I thought.

Ashleigh Nombre
Ashleigh Nombre
2,308 Points

If you have any trouble with other problems my skype is open for questions on these modules. Skype: ashleigh.nombre

Anna Benson
Anna Benson
2,728 Points

Thank you! I may take you up on that sometime!