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 Properties Computed Properties

Arius Eich
Arius Eich
2,769 Points

Computed 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!

enum.swift
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

You 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
Deysha Rivera
5,088 Points

Thank you for your answer. I don't really understand what this has to do with Computed Properties.