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 trialJames Crain
7,967 PointsJust 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
5,898 PointsYou need to use string interpolation for the string values inside the return statement.
Pedro RuÃz
28,105 PointsCould you post the code in question?
James Crain
7,967 PointsSorry 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
5,898 PointsAnd 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
7,967 PointsAwesome. Thanks man, that did it.