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

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