iOS Swift Basics Swift Types String Manipulation

curtis barton
curtis barton
609 Points

interpolated string

how do you assign to an interpolated string

strings.swift
// Enter your code below
let name = "curtis"
let greeting = "Hi, there"

let interpolatedGreeting = "\(Hi, there) \(name)"

3 Answers

Milos Ribera
Milos Ribera
9,631 Points

Hi Curtis! You were close! You just have to interpolate greeting, instead of its value "Hi, there"

It should have to be like this:

// Enter your code below

let name = "curtis"

let greeting = "Hi, there"

let interpolatedGreeting = "\(greeting) \(name)"

Hope it will be useful

curtis barton
curtis barton
609 Points

im not sure why but it still seams to not be working

Milos Ribera
Milos Ribera
9,631 Points

Curtis, I'm sorry I just saw your code and I tried to fix it. Now I checked the Challange.

Into the first step, you have to create a "name" constant of type string, and a "greeting" constant which contains a string and interpolates "name".

let name = "YourName"

let greeting = "Hi there, \(name)"

With interpolating you can easily concatenate strings, but you have to use the variable name instead of its value.

I hope it will be helpful for you

Wouter Willebrands
Wouter Willebrands
iOS Development with Swift Techdegree Graduate 13,121 Points

Hi Curtis,

The first challenge asks you to create two constants. One named name in which you provide your name and a second called greeting that uses the first to create a greeting using interpolation.

let name = "your name" let greeting = "Hi there, (name)"

The answer Milo provided, while correct code, is likely not satisfying the compiler because it provides a solution using 3 properties.

The second part of the challenge asks you to create a constant named finalGreeting. If you are stuck on that part, this is probably why the solution provided is not working, as the compiler for the code challenges is very picky when it comes to naming properties.

Happy coding!