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

Brian Murray
Brian Murray
1,564 Points

Build a Simple iPhone App Code Challenge:Swift Recap Part 1

The following code works in playground but I get an error "... declaring an instance method named description that returns a String.

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: "iOS", author: "Apple", tag: Tag(name: "swift"))

let postDescription = firstPost.description()
Brian Murray
Brian Murray
1,564 Points

Found the problem. I had a space between "description" and the "()"

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: "iOS", author: "Apple", tag: Tag(name: "swift"))

let postDescription = firstPost.description()

'''
Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,734 Points

Weird. I guess leaving out the space is standard practice, but why would the code challenge not compile? Maybe they're checking for it in by searching your code for the text "description()" rather than testing the code by its function.

3 Answers

Marina Alenskaja
Marina Alenskaja
9,320 Points

I don't understand - I have the exact same code, but it gives me an error..

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: "Holiday in Bali", author: "alenskaja", tag: Tag(name: "Holiday"))
let postDescription = firstPost.description()
Marina Alenskaja
Marina Alenskaja
9,320 Points

Aaaah thank you so much, I didn't catch that :-)

Ashleigh Nombre
Ashleigh Nombre
2,308 Points

I still didn't quite get the question but Im going to go back and learn what I missed in the question I didn't realize you need to create a function in order to get the right answer.