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

I don't understand the interpolation part. In other programming languages I can print two string using + between them

I don't understand the interpolation part. In other programming languages such as C++ or java I can print two string using + between their names. for example

println (greeting + language)

and if one of the values of the variables is changed then it is also changed in the print statement.

println.swift
let language = "Swift"

var greeting = "Hello "

println (/greeting  /language)

2 Answers

Nathan F.
Nathan F.
30,773 Points

Those are actually different (but related) features--concatenation and interpolation.

Interpolation allows you to put a variable directly inside of a string, where concat can achieve the same affect by stringing together strings and variables.

You can still actually add strings together. For example:

let myString = "Hello"
let otherString = "World"
let message = myString + otherString
let readableMessage = myString + " " + otherString
print(message)
print(readableMessage)
"HelloWorld"
"Hello World"

Also to interpolate, your syntax needs a fix:

println("\(language) \(greeting)")

Yes I have noticed that I have syntax errors. But your explanation helped make things clearer.

Thank you very much!

All you need to do to print out "Learning Swift" using the constant named language is this:

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