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

I am stumped here...apparently I am printing Learning Swift Swift instead of "Learning Swift"

I am stumped here...apparently I am printing "Learning Swift Swift" instead of "Learning Swift"

What is correct

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

3 Answers

Well - you tell the program to print "Learning Swift" and then you include the variable language that you defined earlier. So you are basically saying "Out put Learning Swift and then follow it with the content of the variable language I set earlier (as Swift)

(language) = "Swift"

You're doing it twice.

John Rainier Rivera
John Rainier Rivera
6,355 Points

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

A println() simply outputs to the console whatever you put in it. You are essentially wanting to print "Learning " + whateverIsInTheLanguageVariable.

To do this you use string interpolation. The syntax is "your string here \(yourVariableHere)" and to get that to output to the console, you would place it in a println() function.