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 trialBoris Likhobabin
3,581 PointsWhy argument name title is not used?
***swift
extension Page {
func addChoice(title: String, story: Story) -> Page {
let page = Page(story: story)
return addChoice(title, page: page)
}
func addChoice(title: String, page: Page) -> Page {
switch (firstChoice, secondChoice) {
case (.Some, .Some): break
case (.None, .None), (.None, .Some): firstChoice = (title, page)
case (.Some, .None): secondChoice = (title, page)
}
return page
}
}
Why in the first addChoice function when we return the second (addChoice(title: String, page: Page)) we don't write the name for the title argument like this : return addChoice(title: title, page: page) ? If I do it this way I get an error "extraneous argument label 'title' in call.
Alternatively why do we need to use page: page instead of just page? In this case the error is missing argument.
So why are these two arguments treated differently? so I'm confused.
1 Answer
Florian Thompson
Courses Plus Student 18,609 PointsHi Boris, the first parameter name is inferred. You if you want to use the first name like addChoice(title: ... ) your addChoice function needs a named parameter.
Which would look like : func addChoice(title title: String, page: Page)
Hope that helped