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 trialAaron Glaesemann
11,303 PointsCan'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.
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
39,021 PointsHi 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
11,303 PointsAaron Glaesemann
11,303 PointsThanks 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
39,021 PointsGreg Kaleka
39,021 PointsYeah it seems that way to me... We'll see if Pasan chimes in. Still possible we're missing something!
Aaron Glaesemann
11,303 PointsAaron Glaesemann
11,303 PointsHey, got it to pass with this:
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
39,021 PointsGreg Kaleka
39,021 PointsInteresting. 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
2,612 PointsKapil Soni
2,612 PointsWhy the question have Text.Headline.style and the code have case mentioned headline in small letter if this is the solution.