Questions tagged [swiftdata]
SwiftData is a Swift-based Apple framework for managed persistence. It combines CoreData persistence technology with Swift’s modern concurrency features.
swiftdata
570
questions
0
votes
0
answers
77
views
SwiftData FatalError Unknown Relationship Key
Some of our users on iOS 17.5+ started to encounter crash due to:
SwiftData/BackingData.swift:669: Fatal error: Unknown Relationship Key - subscription)
We started using SwiftData only on the ...
0
votes
0
answers
52
views
Referencing instance method requires that 'srfidTagData' conform to 'PersistentModel'
So I'm currently running into an issue where when I'm using this library I'm trying to create an array of the tag data inside the model, it worked perfectly fine before with strings but I'm getting ...
0
votes
1
answer
89
views
SwiftData @Query crash when filter parameter is not nil?
I want use dynamically change the Predicate, so that different list can display different data. However, when I click the 'NavigationLink' to get in the ReminderListView() then the app will get stuck, ...
0
votes
0
answers
40
views
Complex model relation in SwiftData
I'm having trouble solving the following problem. I want to create a workout app where the user can see their workout history and exercise progress. To achieve this, I'm using SwiftData to model the ...
0
votes
0
answers
90
views
SwiftData relationships between elements of the same model - can you control or suppress them?
Part of my app involves a genogram (basically a family tree of genetic relations). That means I really only have 1 model type - a Relative, who has relation types to the person at the core of the tree ...
1
vote
1
answer
97
views
How to pass array of SwiftData models to another view?
I have a simple SwiftData query which stores an array of projects. I want to pass this array to a custom view called: "ProjectView" but I get an error that it doesn't find $projects in scope....
1
vote
1
answer
108
views
How to define SwiftData #Index on an enum field?
I am implementing new #Index macro announced at WWDC24 for SwiftData. This is simplified code for my model
import SwiftUI
import SwiftData
enum MyType: Int, Codable {
case Type1
case Type2
case ...
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 ...
0
votes
0
answers
170
views
Proper way to fetch SwiftData models by id
I'm currently working on a simple read operation based on object IDs using SwiftData in my view model. I'm fetching data like this:
func fetch(ids: [String]) {
var models: [SwiftDataModel] = []
...
0
votes
1
answer
55
views
SwiftData updating a Model's property which is a list
I have following problem, please refer to the code below.
In the app I can create an Artist (@Model) and add some Albums (@Model) to it. These are stored and displayed as supposed.
When I'm launching ...
0
votes
0
answers
33
views
How to pass optional Data to the child view to have different functionality based on if data is passed or not in SwiftUI
I have two ways to navigate to make CreateWorkout View, one is the user creating a new workout by tapping on a button in the toolbar:
.toolbar {
NavigationLink() {
...
0
votes
0
answers
84
views
SwiftData binding causes crash on close when a shape is focussed
Very strange issue I'm facing. I am finding that if I have a swiftUI control (such as a slider) with a binding to a property of a swiftData model (such as a Double), and have a separate focusable ...
0
votes
1
answer
110
views
Grouping query results by date
Note:a visually different project
class EventModel {
var eventName: String
var eventDate: Date
var backgroundColor: String
var iconName: String
var notification: Bool
}
@...
-1
votes
1
answer
103
views
How to initialize a singleton with a model container in SwiftUI?
How do I initialize a singleton with a model container while keeping the ability to use @Environment(\.modelContext) private var context throughout my application?
Currently, I'm doing the following ...
0
votes
0
answers
97
views
Creating a temporary copy of a Swift Data Model
I am trying to make a temporary copy of a Swift Data model(Routine), but I get this breakpoint error at get of one of its propery(Routine.worksets). I am assuming this error happens of the ...