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) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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
Reply to How to evolve from an attribute named throws?
If I understand you correctly the issue is that you can't use the word throws in your code as an attribute name but maybe you can work around that by using backticks around it. I know this works fine for variables and properties and in custom types so hopefully it works within a Core Data/SwiftData context as well. So something like this should work, var `throws`: String
Oct ’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
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 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 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 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 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 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 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 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 After upgrading to XCode 16 app stopped working
Your model looks a bit strange to me. Why do you have a many to many relationship between the two models and why do you have an id property of type Float? Is it correct to assume that the float is the actual value (size) here and if so why is then the value also the identifier and why does each value need to be unique?
Replies
Boosts
Views
Activity
Oct ’24
Reply to Swiftdata forcing @Model rename
Looks like you need to perform a migration, see for example https://developer.apple.com/wwdc23/10195
Replies
Boosts
Views
Activity
Oct ’24
Reply to Thread Error with @Model Class
Try to remove the database file so that SwiftData can generate a new one.
Replies
Boosts
Views
Activity
Oct ’24
Reply to SwiftData relationship crash on 17.x
I only use the @Relationship macro at one end of the relationship to avoid any issues. Maybe something has changed in the latest version that allows us to use it at both properties but in your case there is really no reason to do so.
Replies
Boosts
Views
Activity
Oct ’24
Reply to Issues with SwiftData One-to-Many Relationships
https://stackoverflow.com/a/79090346/9223839
Replies
Boosts
Views
Activity
Oct ’24
Reply to How to evolve from an attribute named throws?
If I understand you correctly the issue is that you can't use the word throws in your code as an attribute name but maybe you can work around that by using backticks around it. I know this works fine for variables and properties and in custom types so hopefully it works within a Core Data/SwiftData context as well. So something like this should work, var `throws`: String
Replies
Boosts
Views
Activity
Oct ’24