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 trialAmitai Blickstein
6,863 PointsWhy is `let done = Button.Done("Done")` incorrect?
let done = Button.Done("Done")
1 Answer
Michael Reining
10,101 PointsHi Amitai,
Hmm... that's odd because in my case it accepted the code for part 1.
Here is what I entered.
let done = Button.Done("Done")
For the second part, I created a switch statement inside the function and ended up with something like this.
enum Button {
case Done(String)
case Edit(String)
func toUIBarButtonItem() -> UIBarButtonItem {
switch self {
case Done:
let buttonItem = UIBarButtonItem(title: "Done", style: UIBarButtonStyle.Done, target: nil, action: nil)
return buttonItem
case Edit:
let buttonItem = UIBarButtonItem(title: "Edit", style: UIBarButtonStyle.Plain, target: nil, action: nil)
return buttonItem
}
}
}
let done = Button.Done("Done")
let doneButton = done.toUIBarButtonItem()
Whenever I have trouble with the code challenges, I am open up a new Playground in Xcode and play around with what was provided until I get comfortable with it. I usually solve all challenges first in the Playground before going back to the code challenge. I find it a fantastic tool to help me learn.
I hope that helps,
Mike
PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)
Amitai Blickstein
6,863 PointsAmitai Blickstein
6,863 PointsGlad to know it's a bug over here. This is not the only code challenge where I've gotten inexplicable errors - in fact, every submission has been marked error since a few days ago.