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

P Ku
P Ku
11,100 Points

damn it the code works in playground!

que pasa!?!

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). Filled under \(tag.name) ")
    }
}

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: "swift")
let postDescription = firstPost.description()

5 Answers

P Ku
P Ku
11,100 Points

I meant this line solved the issue (ie, removing the leading and trailing space chars in the string):

return ("\(title) by \(author). Filed under \(tag.name)")
missgeekbunny
missgeekbunny
37,033 Points

It seems to not like your initializer for the struct and wanted you to make the tag in the first post constant.

So instead of

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: "swift")

it wanted

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: (name: "swift"))

That and it may not have liked that you accidentally spelled filled instead of filed.

Edited to add: Your code isn't technically wrong which is why the playground was fine with it. It will compile and work. In fact preview on the compiler had no errors, it's just not how the class wanted you to do it based on my attempts.

P Ku
P Ku
11,100 Points

Thanks for the feedback.

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: (name: "swift"))

results in a compilation error in Playground. The init for struct Post expects a string (not Tag) for the tag.

I tried another version which, again, works in Playground but the online checker barfed again:

struct Tag {
    let name: String
}

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

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

    func description() ->String {

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

let firstPost = Post(title: "iOSDevelopment", author: "Apple", tag: Tag(name: "swift") )

let postDescription = firstPost.description()

Damn again!

P Ku
P Ku
11,100 Points

Is the 'preview' button supposed to show the complication error emitted by the online checker? I clicked on it but all I get is a blank page.

P Ku
P Ku
11,100 Points

Ah, it turned out the online checker hates extra spaces. After I changed:

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

To

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

Then the code passed. Damn it!