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 trialSTEVEN PENA
13,928 PointsCreate a struct named Post with three stored properties:
i need help am close
struct Tag {
let name: String
struct Post {
let title: String
let author: String
let tag: Tag
let firstPost = Post(title: "a string", author: "a string", tag: Tag(name: "aTag"))
}
3 Answers
Patrick Duhamel
5,786 PointsIt seems that the struct Tag is needed for the struct Post and not the opposite. To access a struct within a struct, you need to access it via the first (i.e.: Post.Tag). Also, be sure to close all your brackets. and I don't think that you cannot init a struct wihin the struct itself because it will be not initialized first.
The following code works in playground without errors:
struct Post {
struct Tag {
let name: String
}
let title: String
let author: String
let tag: Tag
}
let firstPost = Post(title: "a string", author: "a string", tag: Post.Tag(name: "aTag"))
Jeff McDivitt
23,970 PointsJust move the instance out of your Struct Post
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
}
let firstPost = Post(title: "Yes", author: "Jim Toms", tag: Tag(name: "Emtpty"))
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are close, all you gotta do is move your instantiation of Post out of the definition of the Post struct. just cut and paste it below the closing curly brace of the Post struct and it will pass.