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

Rubens Neto
Rubens Neto
13,422 Points

Bummer on code challenge.

Hi guys! My code works perfectly in Xcode but is bumming in code challenge. This is the error message: "Make sure you are declaring a method called description that returns a String"

This is my code:

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 tag = Tag(name: "swift")
let firstPost = Post(title:"iOS Development", author:"Apple", tag: tag)
let postDescription = firstPost.description()

Code looks OK to me - I did just try this and got the same result. There may be some glitches that need sorting out. It worked fine when I took the course! Give it some time and try again; it'll get fixed, I am sure. If not, email support with the issue.

One note about your code; your constructor for the firstPost constant can be done in one line without creating the tag constant:

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

Just a pointer! :-)

Steve.

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hey guys:

The compiler is working fine, you just missed one detail, which is hard to notice sometimes. When doing the return on the instance method, you want to use: tag.name

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

This should fix your problem.

Complete Code

struct Tag {
    let name: String
}

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

   // Instance method
    func description() -> String {
        return "\(title) by \(author). Filed under \(tag.name)"
      // tag.name will access the stored property of Tag.
    }

}

// Creating an instance of Post & Tag
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name:"swift"))

// Using the instance method and assigning it to a constant
let postDescription = firstPost.description()

Hope this helps

Haha! Thank you - I was not seeing the wood for the trees!

Steve.

Rubens Neto
Rubens Neto
13,422 Points

Thank you very much Jhoan Arango!!! It solved the problem. =)