When making an init
statement, it will come up with this error: Return from initializer without initializing all stored properties
. What does that mean? 🤷🏻♂️ It would be greatly appreciated if you could give me an explanation and a solution. Thanks! 🙏 Here is the code:
//
// Models.swift
// Vision To-Do
//
// Created by Nicolas Tama on 9/2/23.
//
import Foundation
import SwiftData
@Model
class TodoList {
var title: String
@Relationship(deleteRule: .cascade)
var items: [TodoItem]
init(title: String) {
self.title = title
}
}
@Model
class TodoItem {
var title: String
var isDone: Bool
@Relationship(deleteRule: .cascade)
var items: [TodoItem] = []
init(title: String) {
self.title = title
}
}
Try this:
class TodoList {
var title: String
@Relationship(deleteRule: .cascade)
var items: [TodoItem] = [] // <<--
init(title: String) {
self.title = title
}
}
@Model
class TodoItem {
var title: String
var isDone: Bool = false // <<--
@Relationship(deleteRule: .cascade)
var items: [TodoItem] = []
init(title: String) {
self.title = title
}
}