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

Interpolated Strings? I understand it in the video but can't seem to relay the information to the actual coding of it.

I've tried close to a dozen times I can not seem to get this interpolated string to work correctly.

strings.swift
// Enter your code below

let name = "Max"

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

1 Answer

Okay. So we use string interpolation to insert the value of an expression (a variable, result of a function, mathematical expression) into a string.

let aNumber = 10
print("This string says that the value of aNumber is \(aNumber)")

This code will print "This string says that the value of aNumber is 10" Which means that the expression inside () is evaluated to its value and used in the string.

So the code that you need is:

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

Hope that clears it up.