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

Kanish Chhabra
Kanish Chhabra
2,151 Points

Everything matches to the instructions still code isn't being accepted

What's wrong here? Please help

structs.swift
struct Tag {
    let name: String
}

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

    func description () -> String {
        return "\(title) by \(author). Filed under \(tag)"
    }

}

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: Tag(name: "swift"))
firstPost.description()
let postDescription = firstPost.description()

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're so close here! In fact, you're so close I'm going to give you some hints. First, you have an unnecessary line.

This line doesn't do anything, but doesn't cause the failure of the challenge:

firstPost.description()

You can safely remove this line. Now to the root of your problem. The problem is in your description line here:

return "\(title) by \(author). Filed under \(tag)"

Remember that your tag variable is an instance of the Tag struct. But you're not trying to get the entire struct, you're trying to get the name property from that struct. We use dot notation to access the stored properties of a struct. I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

Hey! I had trouble on this challenge too - Thanks Jennifer! :D This is what I got:

struct Tag { let name: String }

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

func description () -> String {
    return "\(title) by \(author). Filed under \(tag.name)"
}

}

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: Tag(name: "swift")) firstPost.description() let postDescription = firstPost.description()

Steven Parker
Steven Parker
231,269 Points

Hi Elliot, glad to see you resolved your similar issue.

But one suggestion - other readers might enjoy the opportunity to solve the issue from the hints just like you did, so perhaps posting the code spoiler isn't necessary.