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

Richard Pitts
PLUS
Richard Pitts
Courses Plus Student 1,243 Points

Tried and failed, what did I do wrong?

Tried and failed, what did I do wrong?

enums.swift
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!

Dan