Error When Making an init statement on Xcode 15 beta 8

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
    }
}
Answered by Claude31 in 764023022

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
    }
}

It means you are not initializing all your variables in your class. Your Todolist has two variables and you only initialized one. Your Todoitem class has three variables and you initialized one variable. Change your init statements for each class to include the other variables.

Accepted Answer

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
    }
}
Error When Making an init statement on Xcode 15 beta 8
 
 
Q