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

It feels like I'm answering this code challenge correctly. There's no content in the preview, err msg doesn't make sense

It's asking me to assign my value to a constant named doneButton, which isn't in the instructions. Also, when doing that, I still get an error. My code looks identical to the example code except for the different names/types.

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() -> 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 doneButton = BarButton.done(title: "Save")

1 Answer

Dave Harker
PLUS
Dave Harker
Courses Plus Student 15,510 Points

Hi Odell Tuttle,

You've done really well. What you're missing is the last part of the challenge task 2, which asks us to:

Once you have a method, call it on the value we created in the previous task and assign it to a constant named button.

So a quick code entry and you'll be laughing:

let button = done.button()

Great work! and happy coding,
Dave :dizzy:

Thanks Dave