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 trialshane reichefeld
Courses Plus Student 2,232 PointsCan someone explain whats its asking and what each step is doing please
Help
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
}
let firstPost = Post(title: "X", author: "Y", tag: Tag(name: "swift"))
1 Answer
Fernando Boza
25,384 PointsHi Shane lets go bit by bit
struct Tag {
let name: String
}
struct Post {
var title: String
var author: String
var tag: Tag
// by initializing this Struct, you're making it so when you want to use the Struct properties, the title, author and tag. you need to add it in the init.
init(title: String, author: String, tag: Tag) {
self.title = title
self.author = author
self.tag = tag
}
}
// Since the return type of Tag is another Struct names tag, you can see it takes in an parameter or input of a String. meaning you need to add a name. We need to first assign a constant or variable with a Tag struct input.
let testTag = Tag(name: "Fernando")
// After we just add the testTag constant as our Struct tag parameter
let firstPost = Post(title: "Hello", author: "D Shan", tag: testTag)