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

iOS Enumerations and Optionals in Swift Introduction to Enumerations Enum Methods

vivek d
seal-mask
.a{fill-rule:evenodd;}techdegree
vivek d
iOS Development Techdegree Student 1,596 Points

can someone explain how to solve this ?

please explain the question and where i went wrong in my code

buttons.swift
// 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(button: BarButton) -> UIBarButtonItem {
      switch self {
          case BarButton.done(let title):
          return UIBarButtonItem(title: title , style: .done , target: nil , action: nil)
          case BarButton.edit(let title):
          return UIBarButtonItem(title: title , style: .plain, target: nil , action: nil)
      }
    }
}

let done = BarButton.done(title: "Save")
let button = Barbutton.button(button: done)

3 Answers

Hi Vivek,

I responded in your other post - can you let me know how you got on with that?

Steve.

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Vivek,

You're really close. If you read the challenge carefully, you'll notice that it doesn't say for the button() method to take any arguments. There's no reason to pass in a button on a method that's called on a button. That's the other thing you missed - at the end, you need to call the button() method on the constant done that you created in the first challenge (not pass that constant into the method).

If you remove the argument in your method definition, and adjust your last line to call the method properly, you'll be all set.

Cheers :beers:

-Greg