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 trialJoachim Bachstatter
965 PointsIt says I have compiler error but no errors are showing up under the preview tab.
Works fine in xcode playground.
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 "\(self.title) by \(self.author). Filed under \(self.tag.name)"
}
}
let firstPost = Post(title:"iOS Development", author: "Apple", tag:"swift");
let postDescription = firstPost.description()
1 Answer
Steve Hunter
57,712 PointsHi there,
Your Post
struct needs to be created by passing in two strings and a Tag
. While a Tag
has a name
property that is a String
, the init
method for a Post
needs to handle a Tag
object. That's what the challenge tests are passing to your code and it's failing because the Tag
isn't being handled - your init
method is taking three String
instances.
So, when you create the instance of Post
called firstPost
, pass in the two strings as you have done, then create a Tag
instance for the third argument. Something like tag: Tag(name: "Swift")
. You'll need to handle that differently inside init
too - but that's straightforward.
Steve.