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
66
questions
5
votes
1
answer
2k
views
SwiftData EXC_BREAKPOINT when setting relationship
I'm working with SwiftData for the first time and having trouble with crashes when I try to set the value of a relationship.
I have a Profession object which represents a job in the game. Each ...
15
votes
4
answers
9k
views
SwiftData query with dynamic properties in a View
I'm trying to figure out how to make a SwiftUI view that displays data from SwiftData using a query that includes variables passed into the view. I'm guessing that I won't be able to use the @Query ...
17
votes
3
answers
6k
views
SwiftData list bindings with @Query
Since Swift 5.5 we could create SwiftUI lists with bindings like this (e.g. see this answer):
class Item {
// ...
var isOn: Bool
}
struct ContentView: View {
@State private var items: [...
6
votes
2
answers
2k
views
SwiftData Modeling and saving non Nullable Relations
I have the following code:
import SwiftUI
import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
var schoolClass: SchoolClass
var body: some ...
2
votes
1
answer
442
views
SwiftData: Thread 1: "NSFetchRequest could not locate an NSEntityDescription for entity name 'Reminder'"
How do I fix:
Thread 1: "NSFetchRequest could not locate an NSEntityDescription for entity name 'Reminder'
I have read in another post that if I change order of configurations, then it would ...
2
votes
2
answers
2k
views
SwiftData: Migration Error: How to remove all data from Xcode?
I'm supper new on the subject and wanted to create an app that persisted data. I have added two new attributes to the model and my app is crashing devastatingly. I'm getting this error and ...
0
votes
2
answers
979
views
JSON to SwiftData Decode of JSON Ends in Error at ObservationRegistrar
I'm struggling with a SwiftUI app for iOS17 and SwiftData. I am attempting to download data from a JSON source and store the data in SwiftData. I can download and decode the data into a Swift struct, ...
16
votes
2
answers
2k
views
Crash when accessing relationship property of SwiftData model
I have two one-to-many models and I'm getting an unexplained crash when trying to access the relationship properties of the models.
The reason for the error is as follows:
Thread 1: EXC_BREAKPOINT (...
2
votes
1
answer
707
views
SwiftData with ValueTransformer similar to core data
In Core Data, you are able to use ValueTransformer to transform individual attributes to/from core data. This would be useful in cases like encrypting/decrypting certain attributes when storing/...
2
votes
1
answer
177
views
Getting a compiler error trying to write a complicated Predicate
I know there are similar questions out there, like this one for example Combining Predicate in SwiftData but all that looks unnecessary complex to me and I find it difficult to believe that there is ...
1
vote
1
answer
734
views
How to pre-populate an app with a read-only store located in the app's bundle?
I'm trying to preload an app with read-only data contained in a default.store file located in the app's bundle.
import SwiftUI
import SwiftData
@main
struct AppDemo: App {
enum Schema: ...
1
vote
3
answers
1k
views
How do I preview a View that's using @Bindable?
I have a SwiftUI view that is being passed a binding from a parent view. I would like to preview the subview, but can't. I tried .constant and a @Model object directly. Both ways crash the preview.
...
0
votes
1
answer
95
views
Application crash when trying to save (and fetch) a Model with unique attribute a second time
The context is to create a model instance in SwitfData and return it.
This model as a unique attribute (defined by @Attribute(.unique)). The application runs fine the first time but on the second run, ...
0
votes
1
answer
420
views
Swift #Predicate with function usage on the argument
Is it possible to use a #Predicate that part of its expression calls a function (trying to pass that predicate into a SwiftData Query):
func myPredicate(year: Int, month: Int) -> Predicate<MyObj&...
16
votes
6
answers
3k
views
SwiftData IOS 17 Array in random order?
Why is the order of my array random when i use the @Model macro.
class TestModel {
var name: String?
var array: \[TestModel2\]
init(name: String = "") {
self.name = name
...