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

I am stuck and it says make sure you assign to a constant name doneButton

I am stuck and it says make sure you assign to a constant name doneButton

buttons.swift
import UIKit

enum BarButton {
    case done(String)
    case edit(String)

    func button() -> UIBarButtonItem {
        switch self {
        case .done(let value):
            return UIBarButtonItem(
                title: value,
                style: .done,
                target: nil,
                action: nil)
        case .edit(let value):
            return UIBarButtonItem(
                title: value,
                style: .plain,
                target: nil,
                action: nil)
        }
    }
}

let done = BarButton.done("Save")

let doneButton = done.button()

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're fairly close here so, I'm going to give a few hints.

  • The import UIKit is unnecessary and produces a compiler error for me
  • The case done and case edit which take a String should have an external label of title
  • The external label of title should be used when sending in your "Save" string
  • Although the Bummer! message references a constant named doneButton, the instructions say that the constant should be named button. Rename doneButton to simply button

I think you can get it with these hints, but please let me know if you're still stuck! :sparkles:

Thanks Again Jennifer. Jennifer If want to ask questions can I ask directly from you? Can you please share with me your email? I want in some cases if possible ask some learning questions