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 Basics Swift Types String Manipulation

How do I combine a string and a constant in a interpolated constant?

What's wrong with this?

strings.swift
// Enter your code below


let name = "Ivo"
let greeting = "Hi there," + "(name)"

2 Answers

Chris O'Brien
Chris O'Brien
6,544 Points

// Enter your code below

let name = "Chris"

let greeting = "Hi there, (name)"

This needs to have \ in front of (name)

Now I have let greeting = "Hi there, " + "(name)" And I still get an error..

andren
andren
28,558 Points

As Chris O'Brien points out you missed a \ before the (name). But on top of that you are mixing two different techniques of combining strings together.

When you want to combine two strings you can use string interpolation, which is where you write the name of a variable inside of a string surrounded by \(). Like this:

let name = "André"
let message = "Hello \(name)"
// message now equals "Hello André"

Or you can use string concatenation, which is where you combine strings using the + operator. Like this:

let name = "André"
let message = "Hello " + name
// message now equals "Hello André"

This task specifically asks you to use string interpolation, which means that you are not supposed to use string concatenation, or a combination of the two as you have ended up doing.