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 trialAhmed Elkasrawi
2,756 PointsI've ran this code on Playgrounds and I'm confident it works; however I keep getting an error message
The error says that I'm not structuring the description correctly and that I'm not using string interpolation. Only this exercise is preventing me from marking the whole course as completed. Appreciate the help.
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). Filled under \(tag.name)")
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "swift"))
let postDescription = firstPost.description()
1 Answer
tromben98
13,273 PointsHi you put a parenthesis on the last line which caused the error.
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). Filled under \(tag.name)")
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name: "swift"))
let postDescription = firstPost.description
// look on the line above
Best regards Jonas
Ahmed Elkasrawi
2,756 PointsAhmed Elkasrawi
2,756 PointsThanks for the response Jonas; but that's not the reason. "description" is a method and you have to add the parenthesis to call it (as far as i know). removing them causes an error and the code is not compiled.
As i mentioned; this worked fine in Playgrounds. Only on the website quiz it wouldn't work. It should be this line below since in the compiler here it doesn't look like it's understood correctly.
return("(title) by (author). Filled under (tag.name)")