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

John Moron
John Moron
1,658 Points

How do i create a constant named language, println statement which will print the following string: "Learning Swift"

I need help

println.swift
let language = "Swift"

2 Answers

Ethan Lowry
PLUS
Ethan Lowry
Courses Plus Student 7,323 Points

You've got the creating of the constant part down. There are a number of ways you might print it along with a string:

  • By string concatenation ("joining together" of strings):
let language = "Swift"
println("Learning " + language)
  • Or, by string interpolation(a handy way to insert variables or other code into an existing string)
let language = "Swift"
println("Learning \(language)")

Hope that helps.

John Moron
John Moron
1,658 Points

So can use ether way?

Ethan Lowry
Ethan Lowry
Courses Plus Student 7,323 Points

Both will give the same result, most people would prefer the interpolation method in cases like this. I'm not sure whether the Treehouse challenge will accept both, so try the other if it fails :)

John Moron
John Moron
1,658 Points

I understand thanks Ethen:).

Chris Shaw
Chris Shaw
26,676 Points

I'm not sure whether the Treehouse challenge will accept both

Ethan Lowry, this course uses best practises which in this case is interpolation and is what the challenge is expecting and is how the language is taught to students.

Chris Shaw
Chris Shaw
26,676 Points

Hi John,

Earlier we learned about string interpolation which is how we include the value of a variable within a println statement for example, in this task we need to use interpolation to include the value of language within a println declaration.

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

Happy coding!

John Moron
John Moron
1,658 Points

Oh i had to do it like that thanks Chris.