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 trialBekzod Rakhmatov
7,419 PointsWhat am I doing wrong?
I did as in written on quiz but it says error!
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)"
}
}
let firstPost = Post(
author: "Apple",
title: "iOSDevelopment",
tag: Tag(name: "swift")
)
let description = firstPost.description()
3 Answers
Maria Angelica Dadalt
6,197 PointsI did the challenge using your code and I know now what is "wrong". The code checker on this site is VERY perticular about everything, event the order that you write properties and arguments. So you have to change the order of author and title, so the code looks like this:
struct Tag {
let name: String
}
struct Post {
var title: String
var author: String
var tag: Tag
func description() -> String {
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: Tag(name: "swift"))
let postDescription = firstPost.description()
I hope it works now!
Maria Angelica Dadalt
6,197 PointsChange the properties on the Post struct to variables. It worked for me. Also, I think your last constant is misnamed. Shouldn't it be postDescription?
Bekzod Rakhmatov
7,419 Pointsstruct Tag { var name: String } struct Post { var author: String var title: String var tag: Tag func description() -> String { return "(title) by (author). Filed under (tag)" } } let firstPost = Post( author: "Apple", title: "iOSDevelopment", tag: Tag(name: "swift") ) let postDescription = firstPost.description()
I changed but the result is like this "iOSDevelopment by Apple. Filed under Tag(name: "swift")
Maria Angelica Dadalt
6,197 PointsThe interpolation in your method is wrong. You have to use the dot notation to access the name property and the sintax is missing the backslash. It should be like this:
"\(title) by \(author). Filed under \(tag.name)"
Bekzod Rakhmatov
7,419 PointsI think question itself is wrong because Xcode almost shown the result which is correct
struct Tag {
let name: String
}
struct Post {
var author: String
var title: String
var tag: Tag
func description() -> String
{
return "\(title) by \(author). Filed under \(tag.name)"
}
}
let firstPost = Post(
author: "Apple",
title: "iOSDevelopment",
tag: Tag(name: "swift")
)
let postDescription = firstPost.description()
Bekzod Rakhmatov
7,419 PointsBekzod Rakhmatov
7,419 PointsThis is crazy it worked I did not think about it the order also make sense here ! Thanks a lot!