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 Swift 2.0 Enumerations and Optionals Introduction to Enumerations Enum Methods

James Crain
James Crain
7,967 Points

Just wont compile, but compiles fine in an XCode Playground?

For some reason this code won't compile for me, but when I click on the "preview" button, I don't see any errors. That, and when I copy paste all of this example into an XCode Playground, it compiles fine.

Any suggestions would really be appreciated.

Thanks in advance ...

5 Answers

Michael Gamboa
Michael Gamboa
5,898 Points

You need to use string interpolation for the string values inside the return statement.

Could you post the code in question?

James Crain
James Crain
7,967 Points

Sorry about that. I thought I opted for it to be posted w/my question.

Here you go:

enum Button {
    case Done(String)
    case Edit(String)
}

enum Button {
    case Done(String)
    case Edit(String)

    func toUIBarButtonItem() -> UIBarButtonItem {
        switch self {
        case .Done(let doneTitle): return UIBarButtonItem(title: doneTitle, style: .Done, target: nil, action: nil)
        case .Edit(let editTitle): return UIBarButtonItem(title: editTitle, style: .Plain, target: nil, action: nil)
        }
    }
}

let doneButton = Button.Done("Done").toUIBarButtonItem()
Michael Gamboa
Michael Gamboa
5,898 Points

And your constant created in the first video is not initialized. You need to create original constant, and then pass that in with new constant

James Crain
James Crain
7,967 Points

Awesome. Thanks man, that did it.