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 2.0 Basics Swift Types String Manipulation

Justin Bonaccorso
Justin Bonaccorso
2,781 Points

The challenge asks for an interpolated string, I was able to write this in XCode without errors, here I get errors.

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

strings.swift
// Enter your code below
let name = "Justin"
let interpolatedGreeting = "\("Hi there"), \(name)"
Yusuf Akbar
Yusuf Akbar
2,457 Points

Hi Justin,

The challenge asks for two constants to be created. You've created the first one perfectly! Try changing the name of the second constant to the one given in the challenge. Also don't forget about the period/full stop at the end.

I hope this helps :)

Justin Bonaccorso
Justin Bonaccorso
2,781 Points

Thank you Yusuf! I am tryin... I managed to get it looking and acting right in XCode, and have watched the section of video again to make sure I was doing it right, yet I still can't seem to get it to work. I keep trying different things, but I always get a huge amount of errors that aren't too specific. :( I will put below what I have so far... hopefully its something simple that I am missing...

let name = "Justin"

let greeting = "("Hi") (" there"), (name + ".")"

1 Answer

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

From the Apple Docs - String Interpolation

let multiplier = 3
let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"
// message is "3 times 2.5 is 7.5"

When creating a string via interpolation, it is basically the same as defining a regular string. The cool thing is that you can easily include dynamic parts, just wrap them in \(). You can easily combine static and dynamic parts via string interpolation . Let me give you another example

let greeting = "Hello"
let name = "Justin"
let message = "\(greeting) \(name)! Nice to meet you!"
// message is "Hello Justin! Nice to meet you!"

Hope that helps :)

Justin Bonaccorso
Justin Bonaccorso
2,781 Points

That makes sense, I think I got a bit too wild and crazy with the ""s. Thank you!