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 trialZeyad Salah Elhennawi
1,586 PointsI don't know where is the problem
they asked the following : But I don't know what to do exactly... Challenge Task 1 of 2
In the editor you've been provided with a Tag type. Create a struct named Post with three stored properties: title of type String author of type String tag of type Tag
Create an instance of Post and assign it to a constant named firstPost.
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
}
let firstPost: Post
1 Answer
Steve Hunter
57,712 PointsHiya!
You got this! You've got the right idea.
You want to assign an instance of Post
into firstPost
. For that you need an equals sign after let firstPost
. Then, you need to pass in some values for each of the three stored properties you've added to the struct
. So, pass a String
for both title
and author
and a Tag
for tag
.
This looks like:
let firstPost = Post(// stored properties in here)
The stored properties are:
title: "a string", author: "a string", tag: ...
I paused. At this point, you want to create a new Tag
instance. A Tag
is formed with a String
called name
. So this will create a new Tag
:
Tag(name: "aTag")
Add that to the other stored properties above and you get:
title: "a string", author: "a string", tag: Tag(name: "aTag")
Chuck that at the rest of the code and you get
let firstPost = Post(title: "a string", author: "a string", tag: Tag(name: "aTag"))
I hope that makes sense! Shout me if it doesn't!
Steve.