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 trial
Robert Deegan
2,848 PointsInstance method
This code works well in Xcode but TreeHouse doesn't accept it. Ideas?
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 \(firstTag.name)."
}
}
let firstTag = Tag(name: "Mine")
let firstPost = Post(title: "First Post", author: "Me", tag: firstTag)
let postDescription = firstPost.description()
2 Answers
Robert Deegan
2,848 Pointsشكرالك صفوط Thanks, but the problem seems to be with the description. Treehouse says " Make sure the implementation of description matches the directions. Hint: Use string interpolation!". In the playground my result is "First post by Me. Filed under Mine". This would seem to meet the instructions.... "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" Very confusing.
Robert Deegan
2,848 PointsOK. I found the solution. Apparently my coding was good all along. My output was "iOSDevelopment by Apple. Filed under swift." , the period after swift being enough to confuse TreeHouse!
Safwat Shenouda
12,362 PointsGood :)
Safwat Shenouda
12,362 PointsSafwat Shenouda
12,362 PointsThe constant firstTag is defined outside the function. you shoud use tag constant which belongs to the same struct where the function is:
func description() -> String { return "(title) by (author). Filed under (tag.name)." }