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 2.0 Getting Started with iOS Development Swift Recap Part 1

Question about the two structs

I think I am missing something with the two instances?

structs.swift
struct Tag {
    let name: String
}
let ty = Tag(name: "L")

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

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

3 Answers

//it should be either :
let firstPost = Post(title: "T", author: "G", tag:Tag(name:"J"))
or 
let firstPost = Post(title: "T", author: "G", tag:ty)

last parameter tag should in your Post object should receive a Tag struct object, so either you use the object ty you have created earlier or create a a Tag object as shown above

When you create a property in a struct, you assign it a type. In your firstPost object, you gave the tag property an object of type String, not an object of type Tag. In order for this to work you must create an object of type tag either outside of the property declaration of the object or within it, like this:

let obj = Tag(name: "L")
let firstPost = Post(title: "T", author: "G", tag:obj)

//or you can do this:

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

By doing this you're creating an object that has a property of type Tag and not just a property of type String. Hope this helps!

thank you