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 trialSean Lafferty
3,029 Pointsbuilding a simple iphone app
Struggling with the syntax here, specifically the functions parameters! Please help!
Sean
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag = Tag(name: "Bawclaws")
func description()->String {
return "\(title) by \(author). Filed under \(tag)"
}
}
let firstPost = Post(title: "Mr Bungus", author: "Derek Dungal")
let postDescription = firstPost.description()
1 Answer
Jonathan Ruiz
2,998 PointsHey Sean you wrote out the struct Post giving Tag a default name and thats one thing not letting you pass the challenge. The other thing is when you write out the return statement for the method. You have to call the name property since tag is a stored property of Post and its type Tag. When you use string interpolation you have to specify the property with dot notation. It should be written like this.
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.name)"
// if you only put \(tag) it won't come out right
// it will print out, Red Wheelbarrow by Mr. Robot. Filed under Tag(name: "robot")
// adding .name makes it print out the correct phrase
// the phrase you want it like this, Red Wheelbarrow by Mr. Robot. Filed under robot
}
}
let firstPost = Post(title: "Red Wheelbarrow", author: "Mr. Robot", tag: Tag(name: "robot"))
let postDescription = firstPost.description()
You were really close hope this helps