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 Swift Enums and Structs Structs and their Methods Review and Final Exam

Adam Peruta
Adam Peruta
4,919 Points

How to print out the status here?

In this example, how would you print out the status (rather than it just saying Enum Value)?

Adam Peruta
Adam Peruta
4,919 Points

I think I figured it out:

You can just add raw values to the enum and then use:


Am I right?

I don't believe there's a way to do this yet. There's a couple work arounds for this. One of which would be adding a String Description as a raw value to each case. Another way would be to create a func with a switch case I believe which would return a value dependant on self.

2 Answers

Dennis Parussini
.a{fill-rule:evenodd;}techdegree seal-36
Dennis Parussini
Treehouse Project Reviewer

You can. Just add rawValues to the enum

enum Status: String {
        case Doing = "Doing", Pending = "Pending", Completing = "Completing"

        init() {

and then:

var task = Task(description: "Learn Swift", status: .Pending)
Joshua Rystedt
Joshua Rystedt
4,086 Points

I actually worked on this when completing the challenge. My solution was to use a method within the struct.

    func printStatus() {
        let status = self.status
        if status == Task.Status.Completed {
            println("This task has been completed")
        } else if status == Task.Status.Doing {
            println("This task is being done")
        } else if status == Task.Status.Pending {
            println("This task is pending")
        } else {
            println("Error! I don't know what the status is.")