Post

Replies

Boosts

Views

Activity

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
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
Reply to Implementing multiple Model Containers
If you want to do something like this I believe you should have one ModelContainer but with multiple ModelConfiguration objects.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’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?
Replies
Boosts
Views
Activity
Sep ’24
Reply to Migrating schemas in SwiftData + CloudKit
Did you try without a custom migration, since the property has a default value it should work automatically?
Replies
Boosts
Views
Activity
Sep ’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"))
Replies
Boosts
Views
Activity
Sep ’24
Reply to One to Many Relationship in SwiftData
Not cities.country.name but if you have a single city obj selected then city.country.name will work
Replies
Boosts
Views
Activity
Sep ’24
Reply to How to write predicate to express not-in for compound index?
You have a unique requirement on the attribute pair so there is only one Account object that has a given combination of the two attribute. Doesn’t that mean that you can skip the tuple and instead use the id property in your code? That is still use map and the same predicate but with id (or persistentModelId) instead of the tuple?
Replies
Boosts
Views
Activity
Aug ’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:
Replies
Boosts
Views
Activity
Aug ’24
Reply to SwiftData - delete all instances of model causes "Type cannot conform to PersistentModel" error
You are calling the wrong method, instead do modelContext.delete(model: MyModel.self)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to Model Container Sendable Throwing Error in Swift 6
You could create a constant variable and pass that let container = self.modelContext.container someFunc(container: container)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’24