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!

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

iOS Swift 2.0 Enumerations and Optionals Introduction to Enumerations Enum Methods

Quentin L'eilde
Quentin L'eilde
1,907 Points

What is wrong with my code ?

Hi everyone.

I really don't have a clue of what is wrong with my method. Is it the format of my returns ?

(My code is in the enums.swift file)

Thanks for your help

import Foundation

enum UIBarButtonStyle {
    case Done
    case Plain
    case Bordered

class UIBarButtonItem {

    var title: String?
    let style: UIBarButtonStyle
    var target: AnyObject?
    var action: Selector

    init(title: String?, style: UIBarButtonStyle, target: AnyObject?, action: Selector) {
        self.title = title
        self.style = style
        self.target = target
        self.action = action
enum Button {
    case Done(String)
    case Edit(String)

    func toUIBarButtonItem() -> UIBarButtonItem {
      switch self {
        case .Done(let done): return UIBarButtonItem(title: done, style: UIBarButtonStyle.Done, target: nil, action: nil)
        case .Edit(let edit): return UIBarButtonItem(title: edit, style: UIBarButtonStyle.Plain, target: nil, action: nil)

let doneButton = Button.Done("Done").toUIBarButtonItem()

1 Answer

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

Although your code works and it's definitely the shortest way to create your done button, the assignment asks for using the done constant you assigned in the first task Button.Done("Done") in order to create the doneButton.

So this should work:

let done = Button.Done("Done")
let doneButton = done.toUIBarButtonItem()

Hope that helps :)

Quentin L'eilde
Quentin L'eilde
1,907 Points

ok you were right ! I'm french so I certainly misunderstood this instruction... Thanks !