iOS Swift Basics Swift Types Recap: Swift Types

shiny peanut
shiny peanut
4,223 Points

Interpolating string literals

Having a little bit of trouble with string interpolation and how that will work with broken up string literals. I'm not sure that I've seen string interpolation before, honestly.

types.swift
let firstValue = 3
let secondValue = 5
let product = firstValue * secondValue
let output = "\(The product of), \(firstValue), \(times), \(secondValue), \(is), \(product)"

1 Answer

Daniel Turato
PRO
Daniel Turato
Java Web Development Techdegree Graduate 30,108 Points

With String interpolation , you only surround the embedded data with \ () and not the actual normal string writing. So, your output constant should look like this:

let output = "The product of \(firstValue) times \(secondValue) is \(product)"