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 Enumerations and Optionals in Swift Introduction to Enumerations Enums with Associated Values

Richard Pitts
Richard Pitts
Courses Plus Student 1,243 Points

Tried and failed, what did I do wrong?

Tried and failed, what did I do wrong?

enum mobilePhone {
  iphone: String
  android: String
  windowsPhone: String
let 7 Plus = MobilePhone.iphone

1 Answer

Dan Lindsay
Dan Lindsay
39,611 Points

Hi Richard,

First off, when you are creating an enum with associated values, you still have to use the case keyword before the enum member, then put the type inside parentheses. Like this:

enum MobilePhone {
    case iphone(String)
    case android(String)
    case windowsPhone(String)

Also, make sure you use the exact constant name they ask for in the challenge, or it won’t pass. I had it all working in a Playground, but it was continually failing in the challenge until I noticed that I was using iPhone instead of iphone. So if you use this:

let iphone = MobilePhone.iphone("7 Plus")

you should be able to pass the challenge. Hope this helps!