Post

Replies

Boosts

Views

Activity

Reply to SwiftData: This model instance was invalidated because its backing data could no longer be found the store
When you are using @ModelActor you have access to a specific model context for that actor via the property modelContext so you should have try modelContext.delete(… and you should definitely not use the context from the main actor in any other actor. This alone will probably not fix the crash since you have a reference to the deleted objects in self._rooms that you need to clear before doing the delete.
2w
Reply to Picker using SwiftData
The selection parameter for the picker should be a single item and not an array @State private var contractType: TypeOfContract = // some default type also the type of the value passed to .tag() must be the same type as the property above. So this issue is not so much about SwiftData but instead understanding how a picker works.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to Mutating an array of model objects that is a child of a model object
An array is a value type in itself even if the elements are reference types. So if you do var myArray = project.subcategories ?? [] then any change to myArray will not affect project.subcategories but if you make a change to an object in myArray (a Subproject object?) then that object in the project.subcategories array will also be updated. So I guess the short answer is that if you want to add or remove objects to the project you need to work with project.subcategories I can't really help you with the rest because I don't really understand what you are saying in the paragraph after the last code snippet.
Sep ’25
Reply to SwiftData ModelContext.insert crashes, why?
I would keep the ModelContainer as a stored property and create the ModelContext in each test or even better create both the container and context objects in each test. As for the issue with your initial code, the modelContext stored property is a reference to the modelContainer.mainContect but since the modelContainer object is local to the setUp method it will be released and the reference will no longer be valid when that method exits in your second solution the modelContext is a newly created object so it will remain in memory as long as the test is running.
Aug ’25