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

Sandeep Ail
Sandeep Ail
1,569 Points

Cant make out why the following code does not work to complete the challenge.

Says Hint: Use string interpolation. Which I think I am doing and xcode playground is giving me the correct result.

structs.swift
struct Tag {
    let name: String
}

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

    func description() -> String {

        let description = "\(title) by \(author). Filed under \(tag.name) "
        return description

    }

}

let tagName = Tag(name: "Coding")
let firstPost = Post(title: "How to program", author: "Sandeep", tag: tagName )
let postDescription = firstPost.description()

3 Answers

Ali Kayhan
Ali Kayhan
3,331 Points

You probably need to remove the space at the end of the

let description = "\(title) by \(author). Filed under \(tag.name) "
Sandeep Ail
Sandeep Ail
1,569 Points

@ Ali Kayhan, tried that. Doesnt work. Then I tried the following and got a compiler error in the workspace. But it works fine in XCode

struct Tag {
    let name: String
}

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

    init(title: String, author: String, name: String) {
        self.title = title
        self.author = author
        self.tag = Tag(name: name)

    }

    func description() -> String {

        let description = "\(title) by \(author). Filed under \(tag.name) "
        return description
    }
}

let firstPost = Post(title: "How to program", author: "Sandeep", name: "Coding")
let postDescription = firstPost.description()
Ali Kayhan
Ali Kayhan
3,331 Points

Interesting. Because I have just directly copied your code at the first post and the only thing that I have done was to remove the space at the end and it worked, i.e. the challenge was completed. Maybe, you might need to clear the browser cache?

Sandeep Ail
Sandeep Ail
1,569 Points

Yeah that worked. Removing the space before the closing " in the code . :-)

Now I am wondering why my reworked code in the 2nd Post is giving a compiler error and nothing in the debug area.