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 trialMichael Murray
6,037 PointsGetting compile error. Gives the hint: "Use string interpolation". Can someone look at what I have in my code?
My code: 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: "Heat", author: "MICHAEL MANN", tag: Tag(name: "Action")) let postDescription = firstPost.description()
struct Tag {
let name: String
}
Michael Murray
6,037 PointsStefano Mainarde, I tried what you recommended - put self.title, self.author and self.tag.name inside the string interpolation and it worked. Not 100% clear why but I am going to explore further why it needed the self. leaders.
3 Answers
Digvijay Jaiswal
5,565 PointsStefano Mainardi and Michael Murray, guys try the code below...
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)") //tag.name is for accessing the name
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "Swift"))
let postDescription = firstPost.description()
Stefano Mainardi
4,722 PointsThank you. Guys when I got the error I was using the treehouse App on my iPad... So I tried to write the code using the website and it worked. Maybe there's a problem with string interpolation in the app. I noticed that in the sentence "..Apple. Filed under swift" , the word "Filed" changed color from orange to purple, so I think that's the problem.
Digvijay Jaiswal
5,565 PointsStefano Mainardi can you mark the answer as the right answer. It will be easier for others to find.
Stefano Mainardi
4,722 PointsStefano Mainardi
4,722 PointsI'm getting the same error... And I did same as you... The only difference I put self.title, self.author and self.tag.name inside the string interpolation