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 String Manipulation

John Gilmer
PLUS
John Gilmer
Courses Plus Student 3,782 Points

what am I doing wrong?

Not sure what I am doing wrong?

strings.swift
let name = "John"
let greeting = "\("Hi there, ") \(name)"

1 Answer

Jonathan Ruiz
Jonathan Ruiz
2,998 Points

Hi John ! For string interpolation you only put the name of a constant or a variable in the backslash and paranthesis.

let name = "Elliot Alderson" 

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

This reads out. Hi there, Elliot Alderson. When you use string interpolation you have string values in the " " when you call on a constant or variable then you use backslash(randomConstant )

Since you are starting off on Swift I highly recommend having Xcode open and doing the problem in there as well. And always ask yourself if you feel like your learning if you feel like you haven't don't be afraid to restart a section. Also when you are answering a code challenge and have no idea whats the answer after you tried for a while its easier to look up the answer than spend 3 hours on something. From my experience I've spent to much time on certain problems when I should have looked at the answer and then redid the section from scratch.

Hope this all helps try to code everyday if you can it'll help a lot