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

Still have no wrapped my mind around this

Would it be possible to explain what exactly needs to be done and give an example...still bit confused on this part

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)

    let done = 
}

1 Answer

Jaroslaw Adamowicz
Jaroslaw Adamowicz
11,634 Points

Hi,

in this challange you simply need to create new constant with type of this enumeration called BarButton.

In your question code you have:

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

    let done = 
}

This is not ok, because you are still in scope of this enum. So first thing is get out of there!

enum BarButton {
    case done(title: String)
    case edit(title: String)
}

    let done = 

Now, let's ask ourselves how instance of this enum can look like? Well, it can look like this:

BarButton.done(title:"My Cool button")

or like this:

BarButton.edit(title: "Edit")

Of course string for title can be anything, even:

BarButton.edit(title: "I don't care if anybody needs my new edit button anymore!")

:D

But let's get back to our goal here. We need button called "Save" and type .done, here is how it will look like:

BarButton.done(title: "Save")

Now finally, we need to assign this instance to our constatn, right?

It will look like this:

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

but you can also put constatn type explicitly:

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

With explicit type, you can even get rid of enum name before it's value, because Swift will now what it is (but keep the dot!):

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

All in all, your code could look like this:

enum BarButton {
    case done(title: String)
    case edit(title: String)
}

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

I hope it helps ;)

Cheers!

BR, Jarek

I have to say, this is by far the best description I have had to explain something. But this is not what i meant to ask, I meant to ask for the second portion of this question, can i request that you answer the new question in the same manner as you did this one(As in just as descriptive). https://teamtreehouse.com/community/not-to-sure-what-to-do