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 Swift Types Recap: Swift Types

please help me to understand this

using string literal

types.swift
// Enter your code below
let firstValue = 1
let secondValue = 2

let product = 1 * 2
let output = "The product of 1 times 2 is 2"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Yes, you're using a string literal. However, you're supposed to be using string interpolation to build that string literal. Take a look at the first part of the instructions:

Step 2: Using string interpolation, create a string literal that describes the operation we just performed.

String interpolation is a means to tell Swift (and other languages) to insert the string representation of the value of a variable at a given point inside a string literal. Currently, no matter what you change those numbers to, if we printed the output variable it would only ever print "The product of 1 times 2 is 2". We want those numbers to change depending on what our variables are equal to. Take a look at an example:

let studentName = "Joel"
output = "Hi there, \(studentName)"
print(output)

If we were to then print out the value of output, it would print out "Hi there, Joel". The backslash and parentheses indicate that we're going to substitute the value of that variable (no matter what it is) at that point in the string. In this case, it's your name. If we were to go back and change studentName to "Jennifer", it would then print out "Hi there, Jennifer".

Hope this clarifies things, but let me know if you're still stuck! :sparkles: