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 trials t
2,699 PointsEnums Objective 2 -Please give full answer for this objective, none of my code or any code from the answers is passing.
Enums Objective 2 -Please give full answer for this objective, none of my code or any code from the answers is passing.
// Example of UIBarButtonItem instance
// let someButton = UIBarButtonItem(title: "A Title", style: .plain, target: nil, action: nil)
enum BarButton {
case done(title: String)
case edit(title: String)
func button () -> UIBarButtonItem {
switch self {
case .done(let title):
return UIBarButtonItem(title: "Title", style: .Done, target: nil, action: nil)
case .edit(let title):
return UIBarButtonItem(title: "Title", style: .Plain, target: nil, action: nil)
}
}
}
let done = BarButton.done(title: "Save").button()
let button = done.button()
3 Answers
Jeff McDivitt
23,970 PointsHi -
A couple very minor things need changed and this will be correct
enum BarButton {
case done(title: String)
case edit(title: String)
func button () -> UIBarButtonItem {
switch self {
case .done(let title):
//Both .done and .plain should not be capitalized
return UIBarButtonItem(title: "Title", style: .Done, target: nil, action: nil)
case .edit(let title):
return UIBarButtonItem(title: "Title", style: .Plain, target: nil, action: nil)
}
}
}
//Remove the .button()
let done = BarButton.done(title: "Save").button()
let button = done.button()
s t
2,699 PointsHi Jeff,
I did exactly as you suggested; removed capitalization from;
.done and
.plain
then removed .button() from both;
let done = BarButton.done(title: "Save") and
let button = done
I am still receiving an error and can't pass the ojbective.
Here is my exact code:
enum BarButton { case done(title: String) case edit(title: String)
func button () -> UIBarButtonItem {
switch self {
case .done(let title):
return UIBarButtonItem(title: "Title", style: .done, target: nil, action: nil)
case .edit(let title):
return UIBarButtonItem(title: "Title", style: .plain, target: nil, action: nil)
}
}
}
let done = BarButton.done(title: "Save") let button = done
Jeff McDivitt
23,970 PointsYou only need to remove .button() from the first instance not the second
let done = BarButton.done(title: "Save")
let button = done.button()