SwiftData nested Lists
👋 Hey, I have two SwiftData Models and I want to create a nested list with "ItemList" being the parent:
@Model
class Item {
var name: String = ""
var completed: Bool = false
var repeating: Bool = false
var delayUntilTomorrow: Bool = false
var itemList: ItemList?
init(name: String = "", completed: Bool = false, repeating: Bool = false, delayUntilTomorrow: Bool = false) { self.name = name self.completed = completed self.repeating = repeating self.delayUntilTomorrow = delayUntilTomorrow } } AND import Foundation import SwiftData @Model class ItemList { var name: String = "Default"
@Relationship(deleteRule: .cascade, inverse: \Item.itemList) var items: [Item]? = []
init(name: String = "Default") { self.name = name } }
init(name: String = "", completed: Bool = false, repeating: Bool = false, delayUntilTomorrow: Bool = false) { self.name = name self.completed = completed self.repeating = repeating self.delayUntilTomorrow = delayUntilTomorrow } } AND import Foundation import SwiftData @Model class ItemList { var name: String = "Default"
@Relationship(deleteRule: .cascade, inverse: \Item.itemList) var items: [Item]? = []
init(name: String = "Default") { self.name = name } }
2 Replies