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 trialTim Nunn
1,941 PointspostDescription Problem
Any ideas on this one? I am unsure what's missing.
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: "iOS Development", author: "Apple", tag: Tag(name: "swift"))
let postDescription = firstPost.description()
2 Answers
Jaroslaw Adamowicz
11,634 PointsHi,
the problem is with your tag.
You see, in your class tag is type of Tag. And Tag is not a String!
But it has string inside called name. So you can use dot notation to get this name and have what you need.
Instead:
tag
you need to use:
tag.name
So this line with description will look like:
return "\(title) by \(author). Filed under \(tag.name)"
Fix just that and you are good to go!
Cheers!
BR, Jarek
Tim Nunn
1,941 PointsOf course! That did the trick. Thanks