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 Williams
Courses Plus Student 8,059 PointsBuild a Simple iPhone App w/ Swift code challenge
The challenge is pretty simple, yet I can't for the life of me get things to work. Instead, I keep getting the following error:
Bummer! Make sure the implementation of description matches the directions. Hint: Use string interpolation!
I'm going bonkers, because I am using string interpolation and am pretty sure it's exactly what the instructions said it should be. ?
These are the instructions: For this task, add an instance method to Post.
Name the method description
. It takes no parameters and returns a string that describes the post instance. For example given a title: "iOS Development", author: "Apple", and a tag named "swift", the description would read as follows"
"iOSDevelopment by Apple. Filed under swift"
Once you have an instance method, call it on the firstPost
instance and assign the result to a constant named postDescription
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
func description() -> String {
return "\(title) by \(author). Filed under \(tag)"
}
}
let firstPost = Post(title: "iOS Development", author: "Apple", tag: Tag(name:"swift"))
let postDescription = firstPost.description()
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! You're doing great, but you're missing one tiny thing. Remember a tag is a struct too. It has a property called name
. You are trying to get the string for the entire struct, but you should be getting the tag.name
property.
If I replace \(tag)
with \(tag.name)
, your code passes with flying colors!
Michael Williams
Courses Plus Student 8,059 PointsThank you. That makes sense now.