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

Michael Ballew
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Ballew
iOS Development Techdegree Student 1,728 Points

Receiving Compiler Error in Web Editor

My code appears to work fine in Xcode (no warnings no errors), but when I copy it over to the web editor on the Treehouse site I receive a compiler error. It indicated to check the preview tab for errors. None are displayed there. Thanks for any help here.

structs.swift
struct Tag {
  let name: String
}

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

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

    func description() -> String {
        return "\(title) by \(author). Filed under \(tag.name)"
    }

}

let firstPost = Post(postTitle: "iOS Development", postAuthor: "Mike Ballew", postTag: Tag(name: "swift"))
let postDescription = firstPost.description()

1 Answer

Brandon Adams
Brandon Adams
10,325 Points

I could be wrong, but where you have: init(postTitle: String, postAuthor: String, postTag: Tag) maybe you should be initializing the values as title, author, and tag (without the post). Don't structs have built-in init methods anyway?

Michael Ballew
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Ballew
iOS Development Techdegree Student 1,728 Points

You are correct in that the init was unnecessary. Not sure about the variable name. I may go back and see... although Xcode had no issue. I removed the init yesterday after some research. Somebody had done the same thing I was trying and receiving the same error. Weird that Xcode was fine with it. Thanks for your feedback.