Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Enumerations and Optionals in Swift Introduction to Enumerations Enum Methods

Paolo Scamardella
Paolo Scamardella
24,828 Points

Enum challenge task 2 of 2 error message is wrong.

I'm getting an error of "make sure you assign the results of the expression to a constant named doneButton", but in the description, it doesn't states that we need to assign the results to a doneButton variable. I have tried both done and doneButton, but nothing seems to work. I'm assuming team tree house needs to update the task.

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

1 Answer

Sarah Hurtgen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Hurtgen
Treehouse Project Reviewer

Hi! I tried out your code, and the error message does have a typo as far as what the constant should be assigned to - but it's stated correctly in the directions.

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

If you try to assign it to "done" - you'll be calling on the previous tasks value AND trying to assign it to the previous tasks value. If you assign it to "doneButton" as the error suggests (whoops!), it would work in Xcode, but for the purposes of this code challenge, it should simply be assigned to "button".

All your logic is correct though! If you switch doneButton to button, it should let you pass :)

Paolo Scamardella
Paolo Scamardella
24,828 Points

Thanks for the response Sarah, but I have tried all of these options, and nothing works:

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

   // OR

   var done = BarButton.done(title: "Save") 
   done = done.button()

   // OR

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

This has to be an issue on their end.

Sarah Hurtgen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Hurtgen
Treehouse Project Reviewer

I think you may be misunderstanding what I meant, my first explanation was probably a little clunky. Your variable should not be named "done" or doneButton" like the examples you tried -- it needs to be named "button". Again, all your logic is correct! It's just that one word that needs to follow exactly their guidelines. If you copy and paste your initial code, but switch out the very last lines "doneButton" for "button" it will accept.

let button = done.button()

Hope that helps!

Paolo Scamardella
Paolo Scamardella
24,828 Points

Thanks Sarah! That was it! If I read your comment carefully, I would have switched doneButton to button.