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

Paul Je
Paul Je
4,435 Points

Question!

Trouble with the last line, I was told I have to use the description method but I'm not sure how I can implement. Any help would be appreciated!

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: "Catching Fire", author: "Susane Collins", tag: Tag(name: "#hashtagawesomebestsellingbook"))
    let postDescription = description() -> String: firstPost

3 Answers

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

You've nearly got it! You just need to change a couple of things.

In your description function, you need to change "tag" to "tag.name" in your interpolated string. Otherwise, the return value would be "Catching Fire by Susane Collins. Filed under Tag(name: #hashtagawesomebestsellingbook)", rather than "Catching Fire by Susane Collins. Filed under #hashtagawesomebestsellingbook".

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

For postDescription, to call the description function, all you have to do is use dot notation:

let postDescription = firstPost.description()

I hope this helps!

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

Also, I completely agree with the tag. (:

Paul Je
Paul Je
4,435 Points

Thanks!! Wow I need to practice a lot of things, including the dot notation..

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

You're welcome! And don't worry - it's better to know what you need to practice so you can get better at it, than to not know what you need to practice. (: