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

Ben Thompson
Ben Thompson
1,430 Points

I don't know what my struct type is...?

I'm doing the code challenge, and it started me off with a struct called Tag. I created a new struct called Post, and then had to initialize it. But when I try to, it's not accepting it because I can't give a correct Tag type. I thought it would be a string because in the Tag Struct it's only parameter was a String, but it's not working. Thank you for your help.

struct Tag {
  let name: String

struct Post {
    let title: String
    let author: String
    let tag: Tag

let firstPost = Post(title: "Help", author: "Please", tag: "I dont get it")

1 Answer

Thomas Dobson
Thomas Dobson
7,511 Points

Hi Ben,

Lets take a look at an instance creation of Post.

when you create an instance of post, you need to input three variables:

Post(title: String, author: String, tag: Tag)

for your property tag, you have defined it as TYPE TAG within the Post struct. Therefor you create an Instance of Tag, within your Post instance like so:

let firstPost = Post(title: "Harry Potter", author: "JK Rowling", tag: Tag(name: "Bad Books"))

I hope this helps.

Ben Thompson
Ben Thompson
1,430 Points

Thank you. That makes complete sense.