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

I watched the video, if these aren't examples of associated values then what are?

I watched the video, if these aren't examples of associated values then what are?

enums.swift
enum MobilePhone {
    case iphone(String)
    case android(String)
    case windowsPhone(String)


}

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

when I hit check work, I get an error that says " Make sure your enum members contain associated values"

2 Answers

I found out what was wrong. the error I was getting from treehouse was incorrect. I called the member of the enum iPhone instead of iphone because after the directions tell you to label the member "iPhone", they tell you to make sure that you assign the member "iPhone" an associated value.

Also I don't know how to delete this thread, so ill just leave it here.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,526 Points

Hey Greg,

Your code is correct, except a typo, which is causing a compiler error. When I copy/paste your code into the challenge I receive "error: enum type 'MobilePhone' has no case 'iPhone'; did you mean 'iphone'". This is where your typo is. In your assignment to the constant, you have an upper-cased "P" when is should be lower-cased.

Fix that and it's all good!

Nice work! :) :dizzy: