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 trialPaulina Dao
2,148 PointsWhy am I getting a string interpolation error?
Not quite sure why I'm getting a use string interpolation error. Code compiles just fine without any errors but it won't submit.
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
let description = "\(title) by \(author). Filed under \(tag)"
return description
}
}
let firstPost = Post(title: "Title", author: "Author", tag: Tag(name: "tag"))
let postDescription = firstPost.description()
1 Answer
Steven Deutsch
21,046 PointsHey Paulina Dao,
You're just making the most common mistake people have when taking this challenge. For your description, you want to be using String Interpolation on tag's name property. You are currently using interpolation on the tag instance itself. This is not the value we're looking for. You can access the name property of tag by using dot syntax.
I also reformatted your description method to return the string directly instead of storing it in a variable to return afterwards. There's no need to bind the value to a variable/constant here since we will never use the value prior to returning it.
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let firstPost = Post(title: "Title", author: "Author", tag: Tag(name: "tag"))
let postDescription = firstPost.description()
Good Luck