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

Aananya Vyas
Aananya Vyas
20,157 Points

computed properties

it shows nothing in the preview

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

2 Answers

David Papandrew
David Papandrew
8,386 Points

The challenge is case-sensitive. The given enum names are all lowercase (e.g. "headline", "body", "footnote". Update the enum cases and the switch statement so that those names are lowercase and your code should pass.

Enum names are captialized. Enum members are lowercase: this is just a convention. Aananya code works in Swift and the only reason why his /her code fails is because Treehouse is enforcing the convention in its code review. Overall, if Treehouse provides you with set code (the Text enum in this case), it is not a good idea to change it unless they specifically say to do so. Otherwise you can get errors like these.