30 questions
0
votes
0
answers
25
views
How to assign a different ModelContainer to @Query? [duplicate]
My application contains two different databases. The first contains information that does not change and will be distributed in the app's bundle. The second contains information that can be edited and ...
0
votes
1
answer
133
views
Updating view when SwiftData model changes
Edit with minimal reproducible example:
@main
struct SwiftDataTestApp: App {
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Team.self, Player.self
])...
1
vote
1
answer
190
views
SwiftData auto inserts array into modelContext
Definitely one of the stranger quirks of SwiftData I've come across.
I have a ScriptView that shows Line entities related to a Production, and a TextEnterScriptView that’s presented in a sheet to ...
1
vote
1
answer
585
views
Relationship delete not working because an appropriate default value is not configured
SwiftData delete isn't working, when I attempt to delete a model, my app crashes and I get the following error:
SwiftData/PersistentModel.swift:359: Fatal error: Cannot remove My_App.Model2 from ...
0
votes
0
answers
19
views
SwiftData - What are Data / Relationship Faults? [duplicate]
New to data persistence and I'm trying to improve the performance of an app that uses SwiftData. I profiled the app in Instruments, and I saw a lot of data / relationship faults.
What are they and how ...
0
votes
2
answers
537
views
SwiftData 30 seconds delay on autosave
So, since I updated to Xcode 16.1 and iOS 18, my SwiftData project who relies on autosave doesn't work as expected.
Indeed, it works but only after a delay, around 30 seconds.
So if I add something to ...
-1
votes
2
answers
219
views
View is not updated after modelContext.delete(item)
import SwiftUI
import SwiftData
struct ItemListView: View {
@Bindable var luggage: Luggage
@Environment(\.modelContext) var modelContext
@State private var selectedItem: Item?
...
2
votes
2
answers
334
views
SwiftData no such table error for one of models
I have 2 models in my app, fist (ModelA) is working fine - data is persistent no matter how many times I restart app on the simulator, but the second (ModelB) sometimes losts it data and I see errors ...
0
votes
0
answers
208
views
SwiftData Models loses the relationship after the app closes and relaunches
We have an app that uses two SwiftData models in a one-to-many relationship to Log Data given by the user. In the first model we have a date property and an array. Yhe other model is using the one to ...
3
votes
2
answers
3k
views
Changing SwiftData @Model
In my Swift app I had a data model which I needed to remodel.
After that, at the root level of my app, the code crashes when trying to load the ModelContainer, no matter what.
The error is a huge ...
3
votes
0
answers
585
views
SwiftData: Delete rule for many-to-many relationships
I have two SwiftData models, with a many-to-many relationship between them:
@Model
class Movie {
var name: String?
@Relationship(deleteRule: .nullify, inverse: \Actor.movies)
var actors: [...
0
votes
3
answers
670
views
Testing SwiftData models in test target, "failed to find a currently active container"
I'm building out a SwiftData model in the preliminary stages of app development. I'm using test-driven development (tdd) to iterate on the model and iron out kinks prior to integrating the model into ...
0
votes
2
answers
1k
views
Fatal error in ModelContainer.swift line 144 - failed to find currently active container for class
This error only appears in Preview - I am able to run my app fine.
I have a modification sheet that I want to build out in SwiftUI but the preview will not work which is putting a damper on my ...
0
votes
1
answer
706
views
How to create environment objects in SwiftData
In a UIKit-based app where I'm integrating SwiftUI:
class SwiftDataManager {
static let shared = SwiftDataManager()
private init() {}
var container: ModelContainer?
func ...
2
votes
1
answer
338
views
How to create "ENDSWITH" predicate for SwiftData @Query?
I can create all kinds of predicates fine, but I'm not sure what can I use for implement "ENDSWITH"?
extension Filter {
var predicate: Predicate<WordModel>? {
switch self {...