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 Associated Values

challenge task 2 from associated value

The question is create a variable named book and assign it an instance of BookType.PDF with an associated value of "Game of Throne"

i wrote: var book = BookType.Pdf("Game of Thrones") but it doesnt seems to work, did i misunderstand the question? someone please help me thanks.so much!

Michael Cobb
Michael Cobb
2,166 Points

Make sure you are writing the code outside of the curly braces. The code looks good.

thanks very much!! i will try that.

3 Answers

Alan Ng
Alan Ng
13,368 Points
var book = BookType.Pdf("Game of Thrones")

I dont see any difference between your code and mine. did you pass the task 1? try copy & paste my code see if you can pass it

var book = BookType.Pdf case Game of Thrones

enum BookType { // Write your members with associated values here case Pdf(String) case Epub(String)

} var book = BookType.Pdf("Game of Thrones")