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 trialArius Eich
2,769 PointsComputed Properties
I don't know where I was supposed to go with this question and I'm pretty sure it was in a different direction than the one I went in. I really appreciate any help! Thank you!
let UIFontTextStyleHeadline = "UIFontTextStyleHeadline"
let UIFontTextStyleBody = "UIFontTextStyleBody"
let UIFontTextStyleFootnote = "UIFontTextStyleFootnote"
enum Text {
case headline
case body
case footnote
static var style: String {
get {
switch self {
case .headline:
print("\(UIFontTextStyleHeadline)")
case .body:
print("\(UIFontTextStyleBody)")
case .footnote:
print("\(UIFontTextStyleFootnote)")
}
}
}
}
2 Answers
kjvswift93
13,515 PointsYou just need of move the switch statement so that it is inside of the enum so as to check all possible variations.
let UIFontTextStyleHeadline = "UIFontTextStyleHeadline"
let UIFontTextStyleBody = "UIFontTextStyleBody"
let UIFontTextStyleFootnote = "UIFontTextStyleFootnote"
enum Text {
case headline
case body
case footnote
var style: String {
switch self {
case .headline:
return UIFontTextStyleHeadline
case .body:
return UIFontTextStyleBody
case .footnote:
return UIFontTextStyleFootnote
}
}
}
Deysha Rivera
5,088 PointsThank you for your answer. I don't really understand what this has to do with Computed Properties.
Arius Eich
2,769 PointsArius Eich
2,769 PointsThank you!