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 trials t
949 Pointswhy 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?
let language = "Swift"
println("learning" + language)
3 Answers
Steve Hunter
57,712 PointsHi 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.
Stephen McMillan
iOS Development with Swift Techdegree Graduate 33,994 PointsWhat 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
949 Pointsthank you for your help
s t
949 Pointss t
949 Pointsprefect, thank you for your much appreciated help, i'll get the hang of it in the end........ i hope