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!

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

deepak sharma
deepak sharma
3,844 Points

there is an error please help about interpolation

swift_lint.swift:6:22: error: expected ',' separator let greeting = "(Hi there), + ',' + (name)" ^ , swift_lint.swift:6:5: error: 'greeting' used within its own type let greeting = "(Hi there), + ',' + (name)" ^ swift_lint.swift:6:5: error: could not infer type for 'greeting' let greeting = "(Hi there), + ',' + (name)" ^ swift_lint.swift:6:19: error: use of unresolved identifier 'Hi' let greeting = "(Hi there), + ',' + (name)" ^~ swift_lint.swift:6:22: error: use of unresolved identifier 'there' let greeting = "(Hi there), + ',' + (name)" ^~~~~

// Enter your code below

let name = "deepak"
let greeting = "\(Hi there), + ',' + \(name)"

1 Answer

Hi Deepak,

try to change the last line to let greeting = "Hi there, \(name)"

you are getting the error because you're trying to combine string concatenation with string interpolation. It's easier if with string interpolation, just wrap your constant in \(constant) and then you are able to using it in a string literal.

you can read more about string interpolation here https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html#//apple_ref/doc/uid/TP40014097-CH7-ID292