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

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.