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 trialGold Yon War
Courses Plus Student 9,590 PointsWhat is an error?
I don't know what is an error
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
init(title: String, author: String, tag: String){
self.title = title
self.author = author
self.tag = Tag(name: tag)
}
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: "swift")
let postDescription = firstPost.description()
1 Answer
Anjali Pasupathy
28,883 PointsYour code is perfectly functional. The quiz compiler just doesn't like it when your init method takes in a String instead of a Tag for the tag property. Your code should work the way it is, but the quiz compiler doesn't like it. You just need to change your init method to take in a Tag instead of a String:
init(title: String, author: String, tag: Tag){
self.title = title
self.author = author
self.tag = tag
}
After you do this, don't forget to change the instantiation of firstPost so it takes in a Tag rather than a String:
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "swift"))
I hope this helps!