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 trialJonathan Holland
iOS Development Techdegree Student 4,037 PointsI don't see the comments that show the initializer....
I'm not sure what is meant by the last statement in the challenge. Running the method on the previous constant then assigning the value to a new constant named "button"
// 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 dvalue): return UIBarButtonItem(title: dvalue, style: UIBarButtonStyle.done, target: nil, action: nil)
case .edit(let evalue): return UIBarButtonItem(title: evalue, style: UIBarButtonStyle.plain, target: nil, action: nil)
}
}
}
let done = BarButton.done(title: "Save")
let button = done.button()
1 Answer
Royce Pollard
24,267 PointsThe returned value's "style" is not of UIBarButtonItem. But that of BarButton itself.
enum BarButton { case done(title: String) case edit(title: String)
func button() -> UIBarButtonItem {
switch self {
case .done(let dvalue): return UIBarButtonItem(title: dvalue, style: .done, target: nil, action: nil)
case .edit(let evalue): return UIBarButtonItem(title: evalue, style: .plain, target: nil, action: nil)
}
}
Jonathan Holland
iOS Development Techdegree Student 4,037 PointsJonathan Holland
iOS Development Techdegree Student 4,037 PointsOk, but the instructions clearly say: "return a button with style UIBarButtonStyle.done for the done member of the BarButton enum" & "Similarly for the edit member, return a UIBarButtonItem instance with the style set to UIBarButtonStyle.plain."
I didn't think it would know .done is UIBarButtonStyle.done
thanks for help. I finally got passed it :)