Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

0 votes
0 answers
47 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 ...
moonvader's user avatar
  • 20.9k
0 votes
0 answers
34 views

Unable to delete SwiftData object [duplicate]

I am working on migrating my app to SwiftData and testing out some things. I have a custom made toolbar that shows among other things the various objects in a @Model. When I drag one of these to the ...
Jimbo17's user avatar
  • 13
0 votes
0 answers
84 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 ...
Yianni's user avatar
  • 1
0 votes
1 answer
123 views

How to Initialize SwiftData Instances Only on First App Launch?

I need some help with SwiftData. I want to have a few instances of one of my SwiftData classes created only the first time the app opens. These instances should be created once when the app opens for ...
Serafin's user avatar
1 vote
2 answers
343 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 ...
CameronBaba's user avatar
0 votes
1 answer
95 views

Application crash when trying to save (and fetch) a Model with unique attribute a second time

The context is to create a model instance in SwitfData and return it. This model as a unique attribute (defined by @Attribute(.unique)). The application runs fine the first time but on the second run, ...
OlivierM's user avatar
  • 3,082
2 votes
0 answers
144 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: [...
RRR's user avatar
  • 185
0 votes
0 answers
53 views

How to use the .onDelete modifier on a filtered list

I created a small SwiftData project, hosting a list with an .onDelete modifier. In order to filter the list I extracted the list into a separate ListView and set the filter using the init method. But ...
Mat Fetsch's user avatar
0 votes
2 answers
112 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 ...
pkamb's user avatar
  • 34.6k
0 votes
0 answers
55 views

How to keep track of selected child items from an array?

New to SwiftData (and Core Data). In my app, I'd like to keep track of a selected item from a list of items, so it's available when the app is relaunched: @Model class Person { var name: String ...
RRR's user avatar
  • 185
0 votes
2 answers
594 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 ...
Taylor Hartman's user avatar
0 votes
0 answers
443 views

Crash accessing SwiftData model context from environment in a child SwiftUI view in NavigationSplitView resulting in ability to @Query successfully

I have a ChildView that you can access via NavigationLink and that will display in a NavigationSplitView’s detail pane. NavigationSplitView { ListView() } detail: { } And .navigationDestination(for:...
Barrrdi's user avatar
  • 1,111
0 votes
1 answer
337 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 ...
soleil's user avatar
  • 12.8k
3 votes
1 answer
2k views

How to make SwiftData @Query updating from changes made on a background context?

I have a SwiftData @Query in a LazyVStack, works nicely, updates on every model change, even if I make changes in relations only. But I also have a long running task (~3 sec), so I created a @...
Geri Borbás's user avatar
  • 16.4k
1 vote
1 answer
126 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 {...
Geri Borbás's user avatar
  • 16.4k

15 30 50 per page