Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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