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

How do i call a type of struct for my variable?

Hello, I can't call the struct Tag when i want to create a new constant called firstPost. i suppose the mistake already comes from when I defined the constant tag inside the structure Post, but i don't really know how to fix it. Could you help me, please?

structs.swift
struct Tag {
  let name: String
}

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

let firstPost = Post(title: "title", author: "author", tag: "")

2 Answers

Magnus Hållberg
Magnus Hållberg
17,232 Points

Since tag expects a value of type Tag you have to provide that. So "firstPost" could be initialized like this:

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

Oooh, true. Thanks!