You could create a constant variable and pass that
let container = self.modelContext.container
someFunc(container: container)
Post
Replies
Boosts
Views
Activity
You are calling the wrong method, instead do
modelContext.delete(model: MyModel.self)
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)
}
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?
Not cities.country.name but if you have a single city obj selected then city.country.name will work
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"))
Did you try without a custom migration, since the property has a default value it should work automatically?
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?
If you want to do something like this I believe you should have one ModelContainer but with multiple ModelConfiguration objects.
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?
Looks like you need to perform a migration, see for example https://developer.apple.com/wwdc23/10195
Try to remove the database file so that SwiftData can generate a new one.
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.
https://stackoverflow.com/a/79090346/9223839
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