Post

Replies

Boosts

Views

Activity

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) }
Aug ’24
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 Sorting with Complex & Arbitrary Nested Models
You have a complex and dynamic design which will make the whole solution more complex. When you write "...sort the inspections based on the values only in fields with specific labels" it not only is an example of the complexity but it is quite frankly hard to understand how/if it should work. An inspection can have many groups and a group can have many rows so even if you are only sorting on one label with a specific field it will be a complex task to sort the rows and groups for a single inspection not to mention comparing inspections. Since I have no idea what an inspection is in this context and neither what your fields will be filled with it's hard to give any kind of advice but for starters, do you really, really need to sort the inspectors in this manner?
Sep ’24