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

Anika Suares
seal-mask
.a{fill-rule:evenodd;}techdegree
Anika Suares
iOS Development Techdegree Student 601 Points

How to write interpolated strings in swift?

The task was to interpolate a greeting with "Hi,there (Name)" The task instructions were not very clear on how to do this so how do you do this?

strings.swift
// Enter your code below

1 Answer

andren
andren
28,558 Points

"Hi,there (Name)" is not far off from how it is actually done, here is an example demonstrating string interpolation that should be clearer than what they did in the video:

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

Basically you just have a slash and a set of parentheses with the variable you want inserted in the string between those parentheses.