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 trialTanveer Momin
iOS Development Techdegree Student 7,015 Pointsreturn "\(self.title) by \(self.author). Filed under \(bookTag)" not sure why this is not working
I tried it with self.bookTag also.
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
return "\(self.title) by \(self.author). Filed under \(bookTag)"
}
}
let bookTag = Tag(name: "swift")
let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: bookTag)
let postDescription = firstPost.description()
1 Answer
Martin Wildfeuer
Courses Plus Student 11,071 PointsHey there! Almost there, I just added my comments to the code below.
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
// Your code:
// return "\(self.title) by \(self.author). Filed under \(bookTag)"
//
// Just a minor thing, but you do not need self here, as it is unambiguous.
// Moreover, bookTag is not a stored property of this struct, but tag is.
// Additionally, tag is a struct. If you want to access the name, you have to
// use dot notation. The following should work:
return "\(title) by \(author). Filed under \(tag.name)"
}
}
Hope that helps :)