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

Julian Post
Julian Post
955 Points

My code works in the playground but not accepted here

Prints "iOSDevelopment by Apple. Filed under swift" exactly as it should. It may have to do with the fact that I created a constant to hold a version of Tag? Thanks in advance for any help

Would you be able to list which challenge or possibly show your code?

Would you be able to list which challenge or possibly show your code?

Julian Post
Julian Post
955 Points

thanks for replying Carl, don't know why my code isn't there but the below code works, so all good!

2 Answers

Julian, try something like this:

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

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

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

let postDescription = firstPost.description()
print(postDescription)
Julian Post
Julian Post
955 Points

Thank you jcorum! That works great. I can't see the original code anymore, but I'm thinking I didn't declare a version of tag as a constant like you did here. Instead I was trying to pass a value for tag in the firstPost constant, which seemed to work, but I couldn't call it with "tag.name" in the decsription() func