802 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
69
views
Xcode Preview crash with ModelContainer initialization
Background:
I have complex Swift Data models with some Relationships, and at some point, my Xcode Preview is no longer working when I want to init a ModelContainer in it. So I tried to debug and ...
Best practices
0
votes
3
replies
54
views
SwiftData / CloudKit: Best practices for adding / removing to / from a child model object array
In SwiftData / CloudKit, when you have a root model object, it's pretty straightforward when you want to add or delete it from the model: simply use a modelContext variable and use its insert and ...
0
votes
1
answer
69
views
SwiftData shows arbitrary behavior after a few seconds when using two-layer relationship predicate
I have been struggling with arbitrary behavior in SwiftData when using a two-layer relationship in a predicate. I wrote a very simple app to verify this behavior.
I have three models, grandparent, ...
0
votes
1
answer
50
views
SwiftData iOS 26: Model inheritance breaks when another model has relationships to the parent class
I'm testing SwiftData model inheritance (new in iOS 26) and encountering a crash when combining:
A model that inherits from another model
A separate model with relationships to the parent class
...
Advice
0
votes
1
replies
50
views
How to set up SwiftData models for future migrations
I am currently in the middle of developing an iOS app which uses SwiftData. I want to future proof my data models by laying the ground work for data migrations down the line but I am pretty new to the ...
2
votes
1
answer
98
views
Setting a SwiftData filter predicate in a SwiftUI view
I am trying to set a predicate on an array of objects inside a SwiftUI View (and failing to do so)
My data models consist of two independent tables and a third table that holds associations between ...
0
votes
0
answers
78
views
Container Failing to Initialize After a Successful Migration & Initialization
I'm experiencing the following error with my SwiftData container when running a build:
Code=134504 "Cannot use staged migration with an unknown model version."
Code Structure - Summary
I ...
2
votes
1
answer
88
views
SwiftData update causes render with initial data overwriting changes
I'm working on a SwiftUI app using SwiftData, and I'm very new to both frameworks, and swift in general to be honest. I'm trying to create a webview that embeds a monaco editor that will then send the ...
0
votes
0
answers
35
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 ...
Best practices
0
votes
9
replies
123
views
Is there any way to improve SwiftData sort performance for its array variables?
I have two SwiftData models like below:
@Model
final class SDStock {
init() {}
var id = UUID()
var title = "abc"
var code = "123456"
@Relationship(deleteRule: ....
0
votes
1
answer
93
views
No exact matches in call to instance method 'setValue' for custom property
I am trying to use a custom property inside a SwiftData model:
import SwiftData
struct Foo {
var name: String
}
@Model
final class Bar {
var id: String
var name: String
var foo: Foo
...
koen's user avatar
- 5,872
1
vote
2
answers
136
views
SwiftData: context.insert() doesn’t persist data [closed]
I’m new to iOS development and currently learning to persist data using SwiftData.
I’m building a very simple to-do list app to understand how local persistence works.
However, I’ve hit a wall and ...
2
votes
1
answer
272
views
Why does @Model conformance to PersistentModel and Hashable cross into @MainActor isolation in Swift 6.2?
I’m using Swift 6.2 with MainActor set as the default global actor in my project.
When I create a SwiftData @Model that conforms to a protocol extending PersistentModel, I get actor isolation errors ...
1
vote
1
answer
79
views
Where to put the @Relation(inverse) annotation and what are the benefits? [closed]
Obviously it isn't allowed to put the @Relation(inverse)-annotation on both models. Otherwise one receives an error-message about "Circular Reference".
Therefore, should one put the ...
0
votes
1
answer
83
views
Swift binding to dictionary value
I'm working on an app where I have a view AddMonthView where you put in the monthly balance for financial accounts. That account list is dynamic. So I spent some time trying to figure out how to bind ...