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 trialAananya Vyas
20,157 Pointsno errors in editor
cant figure out where is the flaw
struct Tag {
let name: String
}
struct Post{
let title : String
let author : String
let tag : Tag
func description() -> String {
var des = "\(title) by \(author).Filed under \(self.tag)"
return des
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag:Tag(name: "Swift"))
let postDescription = firstPost.description()
print (postDescription)
1 Answer
andren
28,558 PointsThe problem is with the des
string. The tag
constant contains a tag instance, to get access to the name property of that tag instance you need to use tag.name
not just tag
. You also don't need to use self
like you are doing.
In addition to that you are missing a space before the word Filed
in the string. These challenges are very picky about how the string looks so even that is enough to fail the task. If you fix those two issues like this:
struct Tag {
let name: String
}
struct Post{
let title : String
let author : String
let tag : Tag
func description() -> String {
var des = "\(title) by \(author). Filed under \(tag.name)"
return des
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag:Tag(name: "Swift"))
let postDescription = firstPost.description()
print(postDescription)
Then your code will pass.