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 trialTaz Strohmayer
13,887 PointsThis code is compiling and executing correctly in Playground but not in this editor. Am I doing something wrong?
I'm getting the correct result for description
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: "iOSDevelopment", author: "Apple", tag: "swift")
let postDescription = firstPost.description()
2 Answers
Steve Hunter
57,712 PointsHi there,
This isn't working because the challenge is expecting to send two strings and a Tag
into the init
method, not three String
s.
So at the point where you are creating an instance of Post
, create the Tag
instance within the call to Post()
.
Let me know how you get on.
Steve.
Taz Strohmayer
13,887 PointsThanks Steve! That helped tremendously. I got it.
let firstPost = Post(title: "iOSDev", author: "John", tag: Tag(name: "swift"))
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsYes, that fixes the problem but the challenge isn't helping you here at all. Your first task shouldn't pass as that's where the error is, but it does. Then the error messages prompts you to hit 'Preview' which shows you nothing as there's no syntax error. That's unhelpful, to say the least!