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 trialPaul Je
4,435 PointsQuestion!
Trouble with the last line, I was told I have to use the description method but I'm not sure how I can implement. Any help would be appreciated!
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)"
}
}
let firstPost = Post(title: "Catching Fire", author: "Susane Collins", tag: Tag(name: "#hashtagawesomebestsellingbook"))
let postDescription = description() -> String: firstPost
3 Answers
Anjali Pasupathy
28,883 PointsYou've nearly got it! You just need to change a couple of things.
In your description function, you need to change "tag" to "tag.name" in your interpolated string. Otherwise, the return value would be "Catching Fire by Susane Collins. Filed under Tag(name: #hashtagawesomebestsellingbook)", rather than "Catching Fire by Susane Collins. Filed under #hashtagawesomebestsellingbook".
return "\(title) by \(author). Filed under \(tag.name)"
For postDescription, to call the description function, all you have to do is use dot notation:
let postDescription = firstPost.description()
I hope this helps!
Paul Je
4,435 PointsThanks!! Wow I need to practice a lot of things, including the dot notation..
Anjali Pasupathy
28,883 PointsYou're welcome! And don't worry - it's better to know what you need to practice so you can get better at it, than to not know what you need to practice. (:
Paul Je
4,435 Pointshahahaha
Anjali Pasupathy
28,883 PointsAnjali Pasupathy
28,883 PointsAlso, I completely agree with the tag. (: