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 trialFrank Pignataro
7,291 PointsMy code appears to be working correctly in the Xcode playground, with no errors; however does compile.
I get the following error after I enter my code and hit the "Recheck work" button: Bummer: Your code could not be compiled. Please click on "Preview" to view the compiler errors. There is no information (blank page) on the Preview / output.html ; My code appears to be working correctly in the Xcode playground, with no errors. Any help would be greatly appreciated.
Here my code:
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag = Tag(name: "swift")
init(title: String, author: String) {
self.title = title
self.author = author
}
func description() -> String {
print ("\(title) by \(author). Filed under \(tag.name)")
return("\(title) by \(author). Filed under \(tag.name)")
}
1 Answer
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Frank,
Are you sure you posted all your code? You're missing a final closing brace and you don't have either the firstPost or postDescription constants.
Also you have a couple of problems inside your struct. You've created a custom initaliser that takes just a title and an author. But by creating a custom initialiser, you lose the initialiser that Swift gives you for free. And the challenge checker expects to be able to create a struct by providing all the inputs.
For example, it might try to create a test struct with a title of "My Title", author of "My Author" and Tag with a name of "My Tag". It would then expect to get back a struct with matching properties. Your program would crash if given the described test case because you no longer have an initialiser that can accept values for all the struct's properties.
You should delete the custom initialiser and the hard-coded value for Tag.
Cheers,
ALex