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

1 of 1 on Swift So confused

Given the constant named language, write a println statement which will print the following string: "Learning Swift". (Remember to use the language constant within the string you pass to your println statement).

I have tried everything, I dont know what I am doing wrong

println.swift
let language = "Swift"
println("Learning("language")")

5 Answers

Stone Preston has your answer but I could put it into more simple terms.

Basically, the keyword 'let' creates a constant which is basically a variable that can't be changed. the following word 'language' is the name you gave for that constant. "Swift" in quotations like that means you told the computer the 'language' constant will contain the word (Swift). In the println statement you use ( ) to show that what's in between these parentheses is the actual println statement. Now to print "Learning Swift" using string interpolation you would simply write the word "Learning... followed by (language) and close quotations " and parentheses ) . This looks like... println("Learning (language)"). Basically, you took the constant "language" and placed it inside the println statement using the backslash \ and the constant name inside the parentheses ( ).

Hope that helps make it sound simpler.

Stone Preston
Stone Preston
42,016 Points

from the Swift eBook on interpolation for more information on interpolation:

String interpolation is a way to construct a new String value from a mix of constants, variables, literals, and expressions by including their values inside a string literal. Each item that you insert into the string literal is wrapped in a pair of parentheses, prefixed by a backslash:

your current code does not use correct interpolation syntax. you interpolate by writing a \ followed by parenthesis with the name of the variable/constant inside the parenthesis. the interpolation needs to occur inside a string literal (between double quotes):

"this is a variable \(someVariable)"

the correct way to interpolate the language constantinto the string is:

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

interpolation uses a backslash

Thank you * 10

Very helpful.

Anytime! :)

Thank you bro!!!

Kenneth Fong
PLUS
Kenneth Fong
Courses Plus Student 495 Points

thank you! I understand now, I was very confused too!