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 trialBasetis Formacio2
5,936 PointsHow do i call a type of struct for my variable?
Hello, I can't call the struct Tag when i want to create a new constant called firstPost. i suppose the mistake already comes from when I defined the constant tag inside the structure Post, but i don't really know how to fix it. Could you help me, please?
struct Tag {
let name: String
}
struct Post {
let title : String
let author : String
let tag : Tag
}
let firstPost = Post(title: "title", author: "author", tag: "")
2 Answers
Magnus Hållberg
17,232 PointsSince tag expects a value of type Tag you have to provide that. So "firstPost" could be initialized like this:
let firstPost = Post(title: "title", author: "author", tag: Tag(name: "tag"))
Basetis Formacio2
5,936 PointsOooh, true. Thanks!