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

William Hartvedt Skogstad
William Hartvedt Skogstad
5,857 Points

None of these lines work, don't know if there's something wrong with the site..

Challenge Task 2 of 2

We learned about instance methods before. For this task, add an instance method to Post.

Name the method description. It takes no parameters and returns a string that describes the post instance. For example given a title: "iOS Development", author: "Apple", and a tag named "swift", the description would read as follows"

"iOSDevelopment by Apple. Filed under swift"

Once you have an instance method, call it on the firstPost instance and assign the result to a constant named postDescription

structs.swift
struct Tag {
    let name: String
}

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

    func description() -> String {

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

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: Tag(name: "Swift"))

let postDescription = firstPost.description()

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

// let postDescription = firstPost
William Hartvedt Skogstad
William Hartvedt Skogstad
5,857 Points

If I do this:

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

I get an error message saying "Oops! It looks like Task 1 is no longer passing."

2 Answers

Frezy Mboumba
Frezy Mboumba
3,642 Points

Ok I see why The compiler refuses your code. It seems like you are encountering a problem in the second task of the challenge. First of all, you made a mistake in the writing of the method description. I f you try to run the same code in Playground you will figure out what you've done wrong. Your description method is:

          <p>func description() -> String {

        return "\(title) by \(author). Filed under \(tag)"
    }</p>
          ```
But it should be this:

```html
          <p>func description() -> String {

        return "\(title) by \(author). Filed under \(tag.name)"
    }</p>
          ```
You have just forgotten to access the **name** property out of the **tag** parameter. It looks like you were trying to return a struct as a String. Notice that **tag** is not equal to **tag.name**. **tag** is of type **Tag** and is a struct while **tag.name** is a String. 

this is how it should look :


```html
          <p>struct Tag {
    let name: String
}

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


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

}

let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "swift"))

let postDescription = firstPost.description()
</p>
          ```
Hope that's gonna be helpful.
William Hartvedt Skogstad
William Hartvedt Skogstad
5,857 Points

Thanks a lot! That really cleared things up

Reed Carson
Reed Carson
8,306 Points

I remember getting tripped up on this. Remember the var: tag isn't a string like author and title, its an instance of the Tag struct. you need to call tag.name to get the string, calling just tag doesn't return a string.