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 Swift Enums and Structs Enums Enum Members and Raw Values

Robin Nilsson
Robin Nilsson
3,783 Points

Do you need to specify the enum type when creating a variable, or will it infer the type from the member?

Amit mentioned in the video that you don't need to specify the type when changing the value of an enum variable, but I am not if he was implying that you never need to specify the type (including when originally creating the variable), or if it's just not needed once it's already been created.

This is what his code looked like:

var today = Day.Monday
today = .Sunday

1 Answer

Max Hirsh
Max Hirsh
16,773 Points

Yeah, I think he meant that it's not necessary to specify which enum you're starting from after you assign an initial value.