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 Getting Started with iOS Development Swift Recap Part 1

Aananya Vyas
Aananya Vyas
20,157 Points

no errors in editor

cant figure out where is the flaw

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

}

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

1 Answer

andren
andren
28,520 Points

The problem is with the des string. The tag constant contains a tag instance, to get access to the name property of that tag instance you need to use tag.name not just tag. You also don't need to use self like you are doing.

In addition to that you are missing a space before the word Filed in the string. These challenges are very picky about how the string looks so even that is enough to fail the task. If you fix those two issues like this:

struct Tag  {
    let name: String
}
struct Post{
    let title : String
    let author : String
    let tag : Tag
    func description() -> String {
    var des = "\(title) by \(author). Filed under \(tag.name)"
    return des
    }

}

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

Then your code will pass.