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 trialBrian Bellini
3,930 PointsUse of type Tag returning parameter name as well as stored property.
Passed first part of code challenge.
Second part requires me to return a String using interpolation. But returning stored property of tag is "Tag(name: "Swift") not simply "Swift".
I thought it must be a problem with the way I initialised firstPost, but if I remove "Tag(name: "Swift")" and just include "Swift" in a playground I get errors due to it being a String not a Tag type.
I'm sure its something stupid I've done but can't figure it out.
Thanks for the help.
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
let theDescription = "\(title) by \(author). Filed under \(tag)"
return theDescription
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "Swift"))
let postDescription = firstPost.description()
2 Answers
Aniruddha Shukla
2,846 PointsIn your description string you are interpolating the Tag struct. You need to interpolate the variable name on the tag struct.
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
let theDescription = "\(title) by \(author). Filed under \(tag.name)"
return theDescription
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "Swift"))
let postDescription = firstPost.description()
Brian Bellini
3,930 PointsThanks Aniruddha!!!