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 trialAntonija Pek
5,819 PointsHow to see a value of Enum
I managed to write my own code but I have a question regarding an Xcode. On the right panel there is a Enum value but how can see what that value is. For example: I have a new instance and I want to see a status, how can I see it (lets pretend I didn't write that code and I don't know what statuses are available)
2 Answers
miguelcastro2
Courses Plus Student 6,573 Pointsyou can use the rawValue attribute.
Mukul Gupta
8,760 PointsYou can also create a function which displays a String value for the enum you created
enum Status{
case Pending
case Doing
case Completed
init(){
self = .Pending
}
func toString() -> String{
switch self{
case .Pending:
return "Pending"
case .Doing:
return "Doing"
case .Completed:
return "Completed"
default :
return "Not a valid status"
}
}
}
struct Task {
var description : String
var status = Status()
init(description : String){
self.description = description
}
}
var taskOne = Task(description: "Shower")
taskOne.status.toString()
taskOne.status = Status.Completed
taskOne.status.toString()