801 questions
0
votes
0
answers
58
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
81
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
27
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 ...
-12
votes
1
answer
254
views
iOS app crashing in simulator after SwiftData refactor [closed]
I've been working on a small, SwiftUI/SwiftData app for personal usage. This has been going well until yesterday when I decided I should refactor the SwiftData side of things (split some tables up, ...
Best practices
0
votes
9
replies
122
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
81
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
...
1
vote
2
answers
117
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
231
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
75
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 ...
0
votes
0
answers
180
views
Issue with SwiftData inheritance (iOS 26)
Every time I insert a subclass (MYShapeLayer) into the model context, the app crashes with an error:
DesignerPlayground crashed due to fatalError in BackingData.swift at line 908. Never access a full ...
1
vote
1
answer
117
views
How to make a document based app with SwiftData
I have an iOS app that uses SwiftData with @Model types. I’m porting it to macOS and want a document-based app where each window is its own document (like TextEdit). I understand the basic document ...
0
votes
1
answer
125
views
ModelContainers failing to initialize
I need help debugging why my app is failing on hardware trying to initialize the ModelContainer. This is my first app so I may be missing something obvious, but I have two models that I'm trying load, ...
0
votes
0
answers
90
views
Migrating Schema to VersionSchema
I'm very new to SwiftData and have run into an issue where I need to change a datatype in a model. I've attempted to implement a migration plan but my original schema was not of type VersionedSchema ...
1
vote
1
answer
79
views
Reactive global count of model items without loading all records
I need a way to keep a global count of all model items in SwiftData.
My goal is to:
track how many entries exist in the model.
have the count be reactive (update when items are inserted or deleted).
...