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,216 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!