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

Aaron Glaesemann
Aaron Glaesemann
11,303 Points

Can't pass this challenge in Computed Properties. I believe my code is correct or I'm missing something minor. Pls help

I don't understand what is going wrong. Just to be clear, the last two cases I swapped for empty Strings just to test. Previously they had the appropriate values. I've tested this code in Playgrounds with no errors and the output tab in the challenge simulator also gives no errors.

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 ""
        case .Footnote:
            return ""
        }
    }
}

1 Answer

Greg Kaleka
Greg Kaleka
39,019 Points

Hi Aaron,

Yeah... I'm not sure what the problem is here. Your code looks right (with the obvious replacement of empty strings), and I'm getting the same "could not be compiled" error but with nothing in the console. I too ran this in XCode and got the expected output from printing Text.Headline.style. For the record, here's what I think the correct code should look like, which is not passing:

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

}

print(Text.Headline.style) // for checking

Pasan Premaratne can you help us out?

Aaron Glaesemann
Aaron Glaesemann
11,303 Points

Thanks for checking, Greg! I'll assume there must be a bug in the challenge then. I've also tried lower case 'headline' and '.headline' in the case and switch statements with no success. Just because the starter code starts with it in lowercase but the questions asked you to use a capitalized 'Headline' in the question.

Greg Kaleka
Greg Kaleka
39,019 Points

Yeah it seems that way to me... We'll see if Pasan chimes in. Still possible we're missing something!

Aaron Glaesemann
Aaron Glaesemann
11,303 Points

Hey, got it to pass with this:

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

The dot notation .headline must be case sensitive in the challenge. It must check for '.headline' not '.Headline'

So Pasan, if you read this... it's just because I got caught up on the question requesting a capitalized Text.Headline.style ... my bad!

Greg Kaleka
Greg Kaleka
39,019 Points

Interesting. That definitely conforms with standard Swift style, though it would be nice to have some more helpful error messages... Glad you got it to pass!

Kapil Soni
Kapil Soni
2,612 Points

Why the question have Text.Headline.style and the code have case mentioned headline in small letter if this is the solution.