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 trialCody Adkins
7,260 PointsPretty sure I should abandon ship on this problem...
Can someone help me understand the solution a little better?
struct Style {
let UIFontTextStyleHeadline = "UIFontTextStyleHeadline"
let UIFontTextStyleBody = "UIFontTextStyleBody"
let UIFontTextStyleFootnote = "UIFontTextStyleFootnote"
}
enum Text {
case Headline = UIFontTextStyleHeadline
case Body = UIFontTextStyleBody
case Footnote = UIFontTextStyleFootnote
var style: Style {
get {
}
}
}
1 Answer
Greg Kaleka
39,021 PointsHey Cody,
You got a little bit crazy with creating a Style struct! This is a little bit simpler than it seems. The tricky part is that you have to write a switch statement within the enum that switches on self. In other words, when the property style is "gotten", it will check to see which Text it is, and then return the correct string based on that.
Let me know if the code below makes sense, or if you have other questions!
let UIFontTextStyleHeadline = "UIFontTextStyleHeadline"
let UIFontTextStyleBody = "UIFontTextStyleBody"
let UIFontTextStyleFootnote = "UIFontTextStyleFootnote"
enum Text {
case Headline
case Body
case Footnote
var style: String {
get {
switch self {
case Headline:
return UIFontTextStyleHeadline
case Body:
return UIFontTextStyleBody
case Footnote:
return UIFontTextStyleFootnote
}
}
}
}