Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,131 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: