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

Aubrey Clark
Aubrey Clark
4,159 Points

Help? Doing the Final Exam and it keeps telling me "Return from initializer without initializing all stored properties"

Even when I went back and put in the code just like Amit instead of my own, Xcode still tells me "Return from initializer without initializing all stored properties" and "self.status not initialized." Is there something I'm not seeing? Or is this because I'm on a newer version of Swift?

Here's my code:

//To Do Final Exam

import UIKit


// model a Task struct which will have two properties description and status. However, here's the catch to use Status you will have to create your own enum.


enum Status {
    case Doing
    case Pending
    case Completed

    init () {
        self = .Pending
    }
}


struct Task {
    var description: String
    var status: Status

    init(description: String) {
        self.description = description
    }

}

2 Answers

Nicholas Church
Nicholas Church
4,455 Points

I think you have to initialize the status in the task structure.

Aubrey Clark
Aubrey Clark
4,159 Points

I tried that, and after a few tries, I finally got it to work. Thanks!

'''struct Task { var description: String var statusOfTask: Status

init(description: String, statusOfTask: Status) {
    self.description = description; self.statusOfTask = statusOfTask

}

}'''

I'm still not sure why I had to initialize the status in the Task struct when Amit didn't have to, though. Shrug