Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [swiftdata]

SwiftData is a Swift-based Apple framework for managed persistence. It combines CoreData persistence technology with Swift’s modern concurrency features.

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 ...
Kenny Wyland's user avatar
  • 21.3k
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 ...
Mike Bedar's user avatar
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: [...
de.'s user avatar
  • 8,166
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 ...
David Schilling's user avatar
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 ...
Jad's user avatar
  • 136
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 ...
Pouya's user avatar
  • 105
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, ...
JohnSF's user avatar
  • 4,130
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 (...
ikunhub's user avatar
  • 253
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/...
emirrou's user avatar
  • 51
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 ...
grep's user avatar
  • 584
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: ...
parapote's user avatar
  • 862
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. ...
Aaron Bratcher's user avatar
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, ...
OlivierM's user avatar
  • 3,082
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&...
skalber's user avatar
  • 509
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 ...
Florian Liegl's user avatar

15 30 50 per page
1
2 3 4 5