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

jon kelson
5,149 Pointstrying to work out reason for printing one part of code and not the other
import UIKit
var str : String = "Hello " let modernProgrammingLanguage: String = "Swift"
var greeting = "(str)(modernProgrammingLanguage)"// implicit type or inferred type println("To build an iphone app we learn (modernProgrammingLanguage)" )
//Question //This above will print out "To build an iPhone app we learn Swift"
I'm confused , why does it not print of the str "Hello" so it would read "Hello Swift" because the var greeting is asking for str ("Hello") and modernProgrammingLanguage("swift") ?
2 Answers

Fernando Claussen
9,324 PointsYou are assigning Hello Swift to a variable called greeting. That variable is not being used anywhere. On your println you are not using that "greeting" variable.

jon kelson
5,149 PointsThank you Fernando, I can see that now the println is doing the work . So my other question would be is why were we asked to input the line of code
var greeting = "\ (str)\ (modernProgrammingLanguage)"
what does that line of code do if this isn't being used. ?.
or were they just showing that would be a good line of code if you wanted to print out "Hello Swift" ? by using
println "(str)(modernProgrammingLanguage)"
to get "Hello Swift"
ps excuse that lack of backslash the computer removes them as soon as I post .

jon kelson
5,149 PointsThank you it all makes sense now .

Mark Cranston
1,817 PointsI think you may have forgotten you backslash for the string interpolation.
var str : String = "Hello "
let modernProgrammingLanguage: String = "Swift"
var greeting = "\(str)\(modernProgrammingLanguage)"

jon kelson
5,149 PointsSorry mark and thank you yes I did miss out the backlash . But the main question was I was confused as to why the code prints of the lower println code and not the str "Hello" .
jon kelson
5,149 Pointsjon kelson
5,149 Pointssorry when i posted the question it squashed the code up above .