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 trialMichael Ballew
iOS Development Techdegree Student 1,728 PointsReceiving 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.
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
10,325 PointsI 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
iOS Development Techdegree Student 1,728 PointsMichael Ballew
iOS Development Techdegree Student 1,728 PointsYou 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.