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

Farid Rasoolzadeh Baghmisheh
PLUS
Farid Rasoolzadeh Baghmisheh
Courses Plus Student 1,650 Points

I did not initialise the enum, but made an init method in the struct where I initialise the status to .Pending. is OK?

Like this:

enum Status {
    case Doing, Pending, Completed
}

struct Task {
    var description: String
    var status: Status

    init(desc: String) {
        self.description = desc
        self.status = Status.Pending
    }
}

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Farid: Not sure what you are trying to do but yes, that can work.. BUT the only thing is that when you create an instance and then you access the properties of that instance you have to use .hashValue

enum Status {
    case Doing, Pending, Completed
}

struct Task {
    var description: String
    var status: Status

    init(desc: String) {
        self.description = desc
        self.status = Status.Pending
    }
}

var runningTask = Task(desc: "Working on my homework")

runningTask.description
runningTask.status.hashValue