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 trialAdam Peruta
4,919 PointsHow to print out the status here?
In this example, how would you print out the status (rather than it just saying Enum Value)?
Kristofer Doman
18,307 PointsI 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
Treehouse Project ReviewerYou 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
4,086 PointsI 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.")
}
}
Adam Peruta
4,919 PointsAdam Peruta
4,919 PointsI think I figured it out:
You can just add raw values to the enum and then use:
task.status.rawValue
Am I right?