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 trialAndis Slaitas
3,430 PointsStuck with assigment
My code works in XCode, but does not work here. I get a message make sure the value is of type UIBarButtonItem.
enum Button {
case Done(String)
case Edit(String)
func toUIBarButtonItem() -> UIBarButtonItem {
switch self {
case .Done("Done"): return UIBarButtonItem.init(title: "Done", style: UIBarButtonStyle.Done, target: nil, action: nil)
case .Edit("Edit"): return UIBarButtonItem.init(title: "Edit", style: UIBarButtonStyle.Plain, target: nil, action: nil)
default: return UIBarButtonItem.init(title: "Default", style: UIBarButtonStyle.Bordered, target: nil, action: nil)
}
}
}
let done = Button.Done("Done")
let doneButton = Button.toUIBarButtonItem(done)
2 Answers
Andis Slaitas
3,430 PointsI figured it out:
let doneButton = done.toUIBarButtonItem()
Tommy Sollén
3,583 PointsHaha I made the exact same mistake. Thanks for posting your own answer!