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

Rachel Ny
Rachel Ny
3,073 Points

Help on Enum Challenge Task 2. I checked other people's answers and it matches with theirs. I still get an error.Help!

Please help! I get the error "make sure you use the button() function and do not create an instance and assign directly.

But I am creating an instance using the done constant! I don't understand what I'm doing wrong. Please help me!

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 button = done.button()

1 Answer

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

Hi there! I'm not sure how this happened exactly, but somehow you managed to remove a closing curly brace. Take a good look at the number of open curly braces and closed curly braces in your enum definition. You have three open curly braces, but only two closed curly braces. So the compiler thinks your last two lines are part of the enum and won't allow it.

So, if I take your code just like it is and copy/paste it into the challenge but add a closed curly brace between the enum and the let done line, your code passes both steps with flying colors!

Make this correction and give it another whirl! :sparkles: