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
203,121 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 Staff

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: