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

s t
s t
949 Points

why can't i write println?

i am trying to write a println string to display "Learning Swift" with a let named language to represent the word swift.....

let language = "Swift" println("Learning" + language)

what am i doing wrong here?

println.swift
let language = "Swift"
println("learning" + language)

3 Answers

Hi Steven,

You need to use string interpolation for that.

To do this, you include the variable name inside the string you are outputting. You surround the variable name in brackets and precede those with a backslash.

So, rather than:

println("learning" + language)

you get:

println("Learning \(language)")

I hope that works for you.

Steve.

s t
s t
949 Points

prefect, thank you for your much appreciated help, i'll get the hang of it in the end........ i hope

Stephen McMillan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Stephen McMillan
iOS Development with Swift Techdegree Graduate 33,994 Points

What your trying to do is called string interpolation and it's done like so...

let a = "forum"
println("Treehouse \(a).")

What I've wrote above is similar to yours. Instead of using the + sign you simply use a backward slash and parentheses then include the name of your variable or constant inside the parentheses. Eg: \ (variable)

s t
s t
949 Points

thank you for your help