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 (retired) Types Printing Results

Hilton Weeks
Hilton Weeks
285 Points

with interpolation , how would i print if i wanted to use the variable or constant first.

example if my variable was Alice. Example Var = "Alice" , and i wanted to print "Alice says Hi". How would i go about that/

2 Answers

Say,

var name = "Alice"

Then,

"\(name) says Hi!"

should give you what you want?

Steve.

Marcio Mello
Marcio Mello
7,861 Points

I believe it would go like this:

var name = "Alice"

println(" (name) says Hi!")

EDIT: Well, someone replied at the same time as me ;)

You need a backslash before the brackets, I think.

Steve.

Marcio Mello
Marcio Mello
7,861 Points

You are right Steve, my bad. Forgot to add it. Thanks.

EDIT: Actually I did, but for some reason it doesnt display. I wonder why?