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
Matt Shields
2,332 PointsEnums and Optionals - Task 2 - UIBarButtonItem - Can seem to find the answer to this challenge.
I'm not sure if this challenge has been updated recently, but I can't figure out how to pass it. Here are the instructions with the code I posted. Please help. Thanks.
To the button enum, add a method named toUIBarButtonItem that returns an instance of UIBarButtonItem configured properly.
In the buttons.swift file there is a basic implementation of UIBarButtonItem. You can create buttons with three different styles and titles.
Using the associated values as titles for the button, return a button with style UIBarButtonStyle.Done for the Done member of the Button enum. Similarly for the Edit member, return a UIBarButtonItem instance with the style set to UIBarButtonStyle.Plain.
In both cases you can pass nil for target and action. Once you have a method, call it on the value we created in the previous task and assign it to a constant named doneButton.
2 Answers
kjvswift93
13,515 PointsIt should look like this after the second task.
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.button()
Matt Shields
2,332 PointsThanks Kyle but that code didn't pass either.
Matt Shields
2,332 PointsMatt Shields
2,332 Points