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

Issue with task 2 of "Swift Recap 1" code challenge in "Build a Simple iPhone App with Swift 2.0"

I think the code challenge processor is broken. Here's a link to the code challenge:

https://teamtreehouse.com/library/build-a-simple-iphone-app-with-swift-20/getting-started-with-ios-development/swift-recap-part-1

structs.swift
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: "Expert Business Analysis", author: "Audu", tag: Tag(name: "Genius"))
let postDescription = firstPost.description()

6 Answers

Angel Caro
Angel Caro
11,831 Points

I just ran it again and it stopped working but this is the code that worked:

struct Tag {
    let name: String
}

let firstTag = Tag(name: "swift")

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: firstTag)
let postDescription = firstPost.description()

It works in the playground but not in the challenge

Thanks ever so much Angel. The same thing happened to me. It worked in the playground but for some reason doesn't work in the code challenge. I have notified treehouse. Thanks again

Dominik Metzger
Dominik Metzger
4,959 Points

In your code is a space between the function name and the (). And the . at the end of the String is too much. With fixing the two things it worked for me

Angel Caro
Angel Caro
11,831 Points

You have to create a tag with the string "swift" and then print the message "iOS Development by Apple. Filed under swift." replace your firstPost with this:

//Tag
let firstTag = Tag(name: "swift")

let firstPost = Post(title: "iOS Development", author: "Apple", tag: firstTag)  

Replaced it exactly as you advised and it's still not giving me joy

Angel Caro
Angel Caro
11,831 Points

Did you add the firstTag constant above the Post struct? I just ran the code and it passed.

it worked it worked it worked. Thanks again for your help

Bobby Rath
Bobby Rath
4,270 Points

This didn't work for me. Appears to be bugged as it runs in Playground fine.

Angel Caro
Angel Caro
11,831 Points

If it doesn't work you should report it to treehouse sometimes the code challenge environment gets buggy and they will look into it.

Majed Alshammarii
Majed Alshammarii
1,174 Points

I can not do it. Please post it as an answer below. I need it