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 trial

iOS Build a Simple iPhone App with Swift Getting Started with iOS Development Swift Recap Part 1

Monika Kesarwani
Monika Kesarwani
5,851 Points

structure i dont know where I m doing mistake in making instance of structure

struct Tag { let name: String }

struct Post{ var title: String var author: String var tag = Tag() }

let firstPost = Post(title: "Dove", author: "Monika", tag: Tag(name: "MyTag"))

structs.swift
struct Tag {
  let name: String
}

struct Post{
    var title: String
    var author: String
    var tag = Tag()
}



let firstPost = Post(title: "Dove", author: "Monika", tag: Tag(name: "MyTag"))

1 Answer

Steven Parker
Steven Parker
231,269 Points

In the defintion of "Post", you only need to define the argument "tag" by the type instead of creating an instance and performing an assignment:

    var tag: Tag

Happy coding! :christmas_tree: And for some holiday-season fun and extra practice, give Advent of Code a try! :santa:

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Woops! I composed an answer but will remove it as you've gotten a very solid one from Steven Parker! And he's correct, the Advent of Code is awesome :smiley: