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

Zachary Lach
Zachary Lach
1,106 Points

I do not understand why this is not the correct answer let language = "Swift" println("Learning " + language)

The question I was asked was "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)."

the error I was given was

"You need to interpolate the value of the 'language' constant into the string you pass to 'println'."

However, when I type this code into my playground on Xcode the console output = Learning Swift

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

2 Answers

I would do a search for "string interpolation" if I were you. Here's a hint:

\(constant)

consider the difference between concatenation and interpolation. Let me know if this helps you!

Zachary Betz
Zachary Betz
10,413 Points

Apple's documentation on string interpolation says the following:

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.

So, since you are mixing constants and literals in your println() statement, you would write it like this:

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

Mr. Betz, it seems to me that a person asking a question of this nature will not benefit from having the exact answer provided to him. In my opinion, you did the work Mr. Lach could have done on his own. Merely copying and pasting code is certainly not the aim of this kind of forum.

Zachary Betz
Zachary Betz
10,413 Points

James Cool, I see where you're coming from. It all depends on one's learning preference, though. When I post a question to a forum, I am not looking for hints. I am looking for answers. I learn best through tutorials / seeing it done first, so that is why I answered the way I did. As you can see, I linked to the Apple documentation on String Interpolation. I trust that Zachary Lach will read through the docs in his own time to deepen his understanding.