Post

Replies

Boosts

Views

Activity

Reply to SwiftData Relationship Persistence
It doesn't work well when all objects you want to add are new and haven't been inserted before. Try to first insert the Item object before adding the SubItem objects. For example let item = Item(name: "Item1", subitems: []) container.mainContext.insert(item) item.subitems.append(SubItem(name: "subItemA")) item.subitems.append(SubItem(name: "subItemB"))
Sep ’24
Reply to SwiftData multiple loop entries not inserting
You have a single Category object that you update inside the loop instead of creating a new category for each iteration. Remove the category property and change your loop to something like this for index in 0..<model.dataTable!.rows.count { let row = model.dataTable!.rows[index] let name = row["Catagory"] as! String let category = Category(id: UUID(), name: name, instrumen: [[) context.insert(catagory) print(catagory.name) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24