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

Tanveer Momin
seal-mask
.a{fill-rule:evenodd;}techdegree
Tanveer Momin
iOS Development Techdegree Student 7,015 Points

return "\(self.title) by \(self.author). Filed under \(bookTag)" not sure why this is not working

I tried it with self.bookTag also.

structs.swift
struct Tag {
    let name: String
}

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

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

let bookTag = Tag(name: "swift")

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

let postDescription = firstPost.description()

1 Answer

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

Hey there! Almost there, I just added my comments to the code below.

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

  func description() -> String {
    // Your code:
    // return "\(self.title) by \(self.author). Filed under \(bookTag)"
    //
    // Just a minor thing, but you do not need self here, as it is unambiguous.
    // Moreover, bookTag is not a stored property of this struct, but tag is.
    // Additionally, tag is a struct. If you want to access the name, you have to
    // use dot notation. The following should work:
    return "\(title) by \(author). Filed under \(tag.name)"
  }
}

Hope that helps :)