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 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:

task.status.rawValue

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
seal-mask
.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() {
            self.init()
        }
    }

and then:

var task = Task(description: "Learn Swift", status: .Pending)
println("\(task.status.rawValue)")
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.")
        }
    }