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 trialAubrey Clark
4,159 PointsHelp? 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
4,455 PointsI think you have to initialize the status in the task structure.
Aubrey Clark
4,159 PointsI 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