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 trialJulian Post
955 PointsMy code works in the playground but not accepted here
Prints "iOSDevelopment by Apple. Filed under swift" exactly as it should. It may have to do with the fact that I created a constant to hold a version of Tag? Thanks in advance for any help
Carl Smith
8,185 PointsWould you be able to list which challenge or possibly show your code?
Julian Post
955 Pointsthanks for replying Carl, don't know why my code isn't there but the below code works, so all good!
2 Answers
jcorum
71,830 PointsJulian, try something like this:
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let tag = Tag(name: "swift")
let firstPost = Post(title: "iOS Development", author: "Apple", tag: tag)
let postDescription = firstPost.description()
print(postDescription)
Julian Post
955 PointsThank you jcorum! That works great. I can't see the original code anymore, but I'm thinking I didn't declare a version of tag as a constant like you did here. Instead I was trying to pass a value for tag in the firstPost constant, which seemed to work, but I couldn't call it with "tag.name" in the decsription() func
Carl Smith
8,185 PointsCarl Smith
8,185 PointsWould you be able to list which challenge or possibly show your code?