801 questions
0
votes
1
answer
34
views
Custom colors in LineMark?
I'm new to SwiftUI Charts. My basic setup is working fine, except that I need to customize the colors of a multiline chart. The data is coming from two SwiftData classes:
class Parts {
var name: ...
1
vote
1
answer
41
views
SwiftData migration: converting [String]? to [Author]? relationship
I'm migrating a SwiftData model from V1 to V2.
In V1, StoredBook.authors was a [String]?.
In V2, it’s now a relationship to Author objects ([Author]?).
I wrote a custom migration to create Author ...
-1
votes
0
answers
80
views
SwiftData Migration Error: Refactoring existing models into an Inheritance hierarchy (iOS 26)
I am working on refactoring a SwiftData project originally built before iOS 26. I have three existing models—ModelA, ModelB, and ModelC—which share almost identical properties.
Back when I created the ...
2
votes
1
answer
123
views
Fatal 'Index out of range' error when using macOS simulator in Xcode but not when using iOS simulator
I'm completely stumped on this. I can't find anything that clearly explains to me what this code crashes when trying to run in on macOS but runs perfectly when on iOS. I'm very new to SwiftData, and ...
0
votes
1
answer
71
views
Sharing ModelContext between WindowGroup and NSObject
I'm working on a SwiftUI MacOS application that currently has two windows, the primary window, and a command palette window. I'm still pretty new to SwiftUI having only picked it up a couple of months ...
0
votes
0
answers
112
views
Any issue using a SwiftData store with a different Persistence number?
In order to ship a database with my iOS/PadOS app in the most space-efficient manner, I am adding a non-editable store to the app's bundle and referencing it directly. I believe this is the approved ...
-1
votes
1
answer
218
views
SwiftData - limit to one of each matching query
I have a SwiftData model. For the sake of simplicity, the model looks a bit like this:
class LogItem {
var timestamp: Date = Date()
var itemName:String = ""
var itemValue:Int = ...
3
votes
1
answer
135
views
When storing a property with @Attribute(.externalStorage) can we get the url of the file?
In SwiftData, the .externalStorage attribute signifies that we can easily store any binary data adjacent to the database. This seems like a great way to have easily downloaded/cached files. However, ...
1
vote
1
answer
116
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
2
replies
93
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
85
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
89
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
95
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
144
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
88
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 ...