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 trialJeff Olson
2,613 PointsStruct method issue?
The Treehouse checker is insisting there's a compiler error, but my playground is running this code fine. Any ideas what I'm doing wrong?
struct Tag {
let name: String
}
struct Post {
let author: String
let title: String
let tag: Tag
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let thisTag = Tag(name: "coolposts")
let firstPost = Post(author: "Jeff", title: "THE POST", tag: thisTag)
let postDescription = firstPost.description()
struct Tag {
let name: String
}
struct Post {
let author: String
let title: String
let tag: Tag
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let thisTag = Tag(name: "coolposts")
let firstPost = Post(author: "Jeff", title: "THE POST", tag: thisTag)
let postDescription = firstPost.description()
4 Answers
Maria Angelica Dadalt
6,197 PointsOk, I think I know what might be wrong. Try declaring the Post properties as variables. I did them as variables and passed. Also, try inverting their order, with title on top and author in the middle, just as the challenge requests it. They are very perticular about these things...
Maria Angelica Dadalt
6,197 PointsYour thisTag constant wasn't requested for the challenge, that's why the compiler is showing an error. Just assign "coolposts" to the tag instance in firstPost and you should be fine.
Jeff Olson
2,613 PointsI /think/ I've refactored according to your advice, but this is still saying that it can't be compiled (though the preview won't actually show any specific errors) and my playground on my computer is running it just fine.
struct Tag {
let name: String
}
struct Post {
let author: String
let title: String
let tag: Tag
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let firstPost = Post(author: "Jeff", title: "THE POST", tag: Tag(name: "coolposts"))
let postDescription = firstPost.description()
Jeff Olson
2,613 PointsNailed it. The order must not have matched the tests they were using.