TSD
The Swift Den•13mo ago
zeljko

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 } }
2 Replies
aelfled
aelfled•13mo ago
is there a question?
zeljko
zeljkoOP•13mo ago
Yeah, I cannot figure out a way to make this work. I have these two models but I dont know how to use them in SwiftUI. Do you have any code snippets that could help?
Want results from more Discord servers?
Add your server