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

Nay Myo Lwin
Nay Myo Lwin
10,225 Points

code challenge iOS

couldn't pass the test even i have no errors on playground.

also preview didn't show any error. i'm missing anything.

thanks,

structs.swift
struct Tag {
    let name: String
}
struct Post {
    let title: String
    let author: String
    let tag: Tag
    init(title: String, author: String, tag: String){
        self.title = title
        self.author = author
        self.tag = Tag(name: tag)
    }
    func description() -> String {
        return "\(title) by \(author). Filed under \(tag.name)"
    }

}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: "Swift")
let postDescription = firstPost.description()

2 Answers

Hi there,

The tag part isn't quite right. It is of type Tag, not a String. The rest is looking pretty good with some adjustments for that. Try this:

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

So, the Tag is created in the constructor for the Post struct. Your solution is interesting; I think the compiler is looking for something precise, though. I like your method but the tests in the challenge will be expecting to pass a Tag object into the Post struct, not a String.

Make sense?

Steve.

Nay Myo Lwin
Nay Myo Lwin
10,225 Points

wow that's make a lot more sense than what i was doing.

and yes, i passed the challenge =)

thank you very much

No problem - glad to be able to help.

Steve.