799 questions
2
votes
1
answer
66
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 ...
Best practices
0
votes
9
replies
121
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: ....
1
vote
2
answers
111
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 ...
1
vote
1
answer
78
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
0
answers
177
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 ...
0
votes
1
answer
122
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, ...
1
vote
1
answer
75
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).
...
1
vote
1
answer
64
views
How can I use a model from DocumentGroup alongside one from .modelContainer in Swift Data?
I’m building a document‑based Swift UI app using DocumentGroup with SwiftData. I want:
A document‑scoped model (Gate) that is persisted inside a file
An app‑scoped model (User) that is stored in the ...
1
vote
0
answers
67
views
Sync not working for independent watchOS app using CloudKit and SwiftData
I'm working on an independent watchOS app and I was looking for the best solution to persist data locally and have an online sync with the iCloud storage.
I've found out about the SwiftData which is ...
0
votes
0
answers
44
views
Swift 6: “Main actor-isolated conformance of FeelingType to Encodable cannot be used in nonisolated context” with SwiftData @Model [duplicate]
I’m migrating a small SwiftData model from Swift 5 to Swift 6. The same code compiles under Swift 5, but with Swift 6 it fails when the @Model macro expands a property whose type conforms to Codable.
...
4
votes
2
answers
376
views
How do I refresh a SwiftData (manual) fetch whenever the database is changed?
Summary
I have a View Model class, paired with a SwiftUI View, that fetches filtered entries from SwiftData using a ModelActor. I've used SwiftUI's .task(id:) to trigger re-loads in the View Model ...
0
votes
2
answers
240
views
Inheritance in SwiftData with iOS 26.0 and Xcode beta
Hello, I'm trying to create a simple app with inheritance and SwiftData. Unfortunately, I keep getting the same error with this example:
Thread 1: Fatal error: Never access a full future backing data ...
0
votes
0
answers
71
views
SwiftData External Storage Option iCloud Sync
In my SwiftData model one of the properties is set to Data? with externalStorage option. So, it means that it will not be stored in the actual database but a reference will be in the database and file ...
1
vote
1
answer
207
views
How Can I Retrieve All SwiftData Values at Runtime?
I'm working with SwiftData and trying to replicate behavior similar to what I used to do with CoreData, where I had an extension on NSManagedObjectContext that allowed me to fetch all stored objects, ...
1
vote
1
answer
356
views
Generic parameter 'V' could not be inferred while ForEach in sectioned results
I'm using the swiftdata-sectionedquery package. It basically allows SwiftData to have a SectionedFetchRequest. The problem I am running into is I keep getting this error whenever I try to foreach on ...
0
votes
0
answers
78
views
Why doesn’t onChange(of: @Query results) fire when a SwiftData model’s property changes?
Problem Description
When using SwiftUI's @Query with SwiftData models, I encountered confusion about reactivity triggering. In certain situations, SwiftUI's reactivity mechanism doesn't work as ...
0
votes
0
answers
46
views
Why @Query ignores search term? [duplicate]
I have this code:
import SwiftUI
import SwiftData
@Model
final class Item {
@Attribute(.unique) var id = UUID()
private(set) var name: String
init(name: String) {
self.name = ...
0
votes
0
answers
112
views
I am getting sporadic crashes since updating Swift ModelContainer
I have some models in my app:
[SDPlanBrief.self, SDAirport.self, SDChart.self, SDIndividualRunwayAirport.self, SDLocationBrief.self]
SDLocationBrief has a @Relationship with SDChart
When I went live ...
0
votes
0
answers
32
views
Predicate Error: "Captured/constant values of type 'xxx' are not supported" [duplicate]
I'm working with SwiftData and trying to filter my data using predicates with a custom enum, but I'm getting an error when the predicate executes:
SwiftDataError(_error: SwiftData.SwiftDataError....
3
votes
1
answer
52
views
SwiftUi error when trying to navigate to a view with a SwiftData model context
I'm doing the SwiftData tutorial on Hacking With Swift, and I'm trying one of the challenges which is to add a swipe to delete on a list of related models. I thought I had the right idea, but I'm ...
1
vote
0
answers
51
views
NSPersistentHistoryToken to DefaultHistoryToken in SwiftData
Is it possible to convert a NSPersistentHistoryToken to a DefaultHistoryTransaction.TokenType (DefaultHistoryToken)?
func subscribeToModelChanges() async {
NotificationCenter.default.notifications(...
0
votes
1
answer
135
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
])...
0
votes
0
answers
99
views
ShieldConfigurationExtension & SwiftData
I am developing a Screen Time App for iOS and I am having issues with the ShieldConfigurationExtension (ShieldConfigurationDataSource). I know this extensions is sandboxed but I should be able to read ...
1
vote
1
answer
353
views
How to completely reset SwiftData programatically?
I'm currently developping an app, which runs on several devices via TestFlight. Since I am still in an early stage my @Models are subject to change quite frequently.
I know that the preferred way of ...
1
vote
0
answers
128
views
SwiftData Transformable Attribute Error with Empty Arrays
I'm encountering an error when trying to save a SwiftData entity with a transformable attribute that should handle an array of strings. The error occurs specifically when the array is empty.
The Error
...