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

brad agoos
brad agoos
284 Points

interpolation question

I was able to have my computer's Xcode playground and console print the desired outcome of a line that said "Learn Swift". But I keep getting the error from the lesson that I need to interpolate. I don't understand why I would need to bc I get the seemingly desired result of "Learn Swift". Also, the question doesn't seem to ask to interpolate which was only gone over in a "var" line of the code in the lesson. Any thoughts?

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

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, Brad, what you're doing with your println output String isn't wrong, it's called string concatenation, a way of combing 2 or more String using the plus signs, and it'd produce the same result.

But the challenge asks for is string interpolation.

println("Learning \(language)")

Like this, without using the plus sign, you enclose variable/constant by \() and inject its value directly into the println String.

brad agoos
brad agoos
284 Points

William-thanks for your reply. Two things- 1. the challenge didn't ask for/require interpolation although the error message seems to suggest that it is looking for it. 2- I actually did the exact line of code you suggested but when I enter that SAME line of code it still tells me that I need to "interpolate the value of the 'language' constant into the string i pass into 'println' " which both you and I already did?? Confused. Do you think it wants some other type of interpolation or is this a bug??

William Li
William Li
Courses Plus Student 26,868 Points

1 Actually it did, though the wording is a bit different

Remember to use the language constant within the string you pass to your println statement, yes. That means interpolation

2 I wonder if u made any change to the let statement in line 1? This is original code provided by challenge, don't modify it, otherwise it may not pass the grader, just add the println statement on the next line

Imgur