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 Intermediate Swift 2 Properties Computed Properties

Florian Groussin
Florian Groussin
4,563 Points

How could I understand it?

Hello, I don't get this one at all but if someone could bring me a hint with his light it will be wonderful. I don't understand the question and don't get how I could return "UIFontTextStyleHeadline". Maybe by assigning to each case of the enum the corresponding constant?

The question must be as clear as my head is now, hope you can help me.

Thank you in advance and enjoy your day.

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

What you want to do in the computed property is a switch that will switch the enum as "self", and in each case you return the corresponding constant.

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
        }
    }
}

Good luck

Florian Groussin
Florian Groussin
4,563 Points

hello as you explain it it seemed so simple... Thank you very much for your help i think I will get it now :)

Enjoy the rest of the day pal