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 trialOlivier de Broqueville
1,013 PointsI get a "Bummer¨" compiler error message. But no error is shown!
After checking my work, I get a compile error message, but selecting the Preview tab shows a blank screen!
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
init(title: String, author: String, name: String) {
self.title = title
self.author = author
self.tag = Tag(name: name)
}
func description() -> String {
return "\(self.title) by \(self.author). Filed under \(self.tag.name)"
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", name: "swift")
let postDescription = firstPost.description()
1 Answer
Steve Hunter
57,712 PointsHi Olivier,
You're getting an error here because your Post
struct isn't quite working as expected. The tests in the challenge are expecting to be able to send an instance of Tag
into Post
when creating a new Post
instance. Your code doesn't allow this as it wants a String
to be sent in.
You have everything correct except for this. So, delete your init
method. You don't need it. Then, in your call to create a Post
instance, create a Tag
instance and send in a name
property as you create a new instance inside the constructor/init call for the Post
struct. (And lose the self.
bits in your description
func
- they work but aren't needed).
That all looks like:
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: Tag(name: "swift"))
let postDescription = firstPost.description()
Let me know how you get on.
Steve.
Olivier de Broqueville
1,013 PointsOlivier de Broqueville
1,013 PointsI see, Thank you, Steve.