Questions tagged [swift-data]

Swift Data is a data modeling framework from Apple for use in apps running on their operating systems, including iOS, macOS, and others. It's closely related to Core Data but is used in different, more Swift-friendly ways.

92 questions
0
votes
0 answers

Swiftdata three level relationship not working in SwiftUI preview

There is a 3 level relationship in my model: Parent(One) -> Child(Many) -> GrandChild(Many) The way it is set up is working fine in the simulator, but the preview crashes when adding code to manipulate the GrandChild. Am I doing something wrong? The…
HugoLXO
  • 222
  • 3
  • 10
0
votes
2 answers

I don't understand how should set up this relationship using SwiftData

In my testing project, the user inserts a flight that has a destination airport and an arrival airport, here is my code: Something has to be wrong with my relationship between flight and the airport but not sure how it needs to be written the…
Damiano Miazzi
  • 1,514
  • 1
  • 16
  • 38
0
votes
0 answers

How to access same SwiftData Model Container inside Observable Store

I am trying to access same model container inside Observable class which i have provided to Scene var body: some Scene { WindowGroup { ContentView() }.modelContainer(for: [Product.self] I can access this model inside View as…
shoji
  • 103
  • 3
0
votes
1 answer

Query() in view with model container attached shows error saying it does not have a model container

I have a function on a view that has a modelContext on its environment and that can successfully add data to the model container. But when in that same function I try to run a Query() function call I get this message on the console: Set a…
José María
  • 2,835
  • 5
  • 27
  • 42
0
votes
0 answers

How can I have two stores of the same SwiftData model?

I have this simple model: @Model class BasicTrainInfo { @Attribute(.unique) let number: String @Attribute(.unique) let technicalNumber: String init(number: String, technicalNumber: String) { self.number = number …
José María
  • 2,835
  • 5
  • 27
  • 42
0
votes
1 answer

Combining Predicate in SwiftData

I'm trying to combine multiple Predicates of the Type with and / or. Previously with CoreData and NSPredicate I'd just do this: let predicate = NSPredicate(value: true) let predicate2 = NSPredicate(value: false) let combinedPred =…
nOk
  • 2,725
  • 4
  • 13
  • 26
0
votes
1 answer

onDelete Does not Reliably Delete List Items in SwiftData NavigationSplitView

I'm building a new version of an app with SwiftData and am having issues with list deletions in iPad landscape mode. When deleting items, the deleted item randomly reappears as though not deleted from the context. I have included code for a very…
JohnSF
  • 3,736
  • 3
  • 36
  • 72
0
votes
0 answers

What is the purpose of the "transformable" option in the @Attribute macro?

The new SwiftData macro @Attribute provides a .transformable option. From the apple doc: Transforms the property’s value between an in-memory form and a persisted form. This description is rather unclear. What is the purpose of this option and…
parapote
  • 433
  • 2
  • 8
0
votes
0 answers

SwiftData relationship fault not occuring when fetching the model

This may or may not be a bug or my misimplementation. When two objects have a relationship with each other one is usually faulted until it is being used in order to preserve space in the memory. This is the default behavior in CoreData. However, I…
Blacksmith
  • 199
  • 7
0
votes
0 answers

Im creating expenses app with by using 2 different Model Transaction and Category Model. and always failed to add category to the transaction

im pretty new on the SwiftUI so I dont how face this issue. Currently im creating expense app for my learning. Im still not understand how the model works. in this case I have 2 different model Transaction and Category @Model class…
0
votes
0 answers

Getting crash in SwiftData - Relationship(.cascade)

I tried retrieve value from this model object. getting crash here. Here I didn't insert any data in table. but I init a new object in variable and getting the default values to local @State variables. @Model final class CompanyDetail:…
Kathiresan Murugan
  • 2,783
  • 3
  • 23
  • 44
0
votes
1 answer

SwiftData @Query: 'Query' is ambiguous for type lookup in this context

I'm trying out SwiftData and came across the following error when trying to use @Query: 'Query' is ambiguous for type lookup in this context import FirebaseFirestore import SwiftData struct ContentView: View { @Environment(\.modelContext) var…
Stoic
  • 945
  • 12
  • 22
0
votes
0 answers

Lightweight Migration Issues in SwiftData

I am trying to run a lightweight migration in which I am changing the name of a model property from name to title. The database is already populated with few records. Those records must be preserved. Here is my schema versions: enum TripsSchemaV1:…
azamsharp
  • 19,710
  • 36
  • 144
  • 222
0
votes
0 answers

Swift Data Error "The model configuration used to open the store is incompatible with the one that was used to create the store."

While developing an iOS app with Xcode Beta 14 I changed a swift-data model and I started getting this error: Error Domain=NSCocoaErrorDomain Code=134020 "The model configuration used to open the store is incompatible with the one that was used to…
Ronan18
  • 1
  • 1
0
votes
1 answer

Cannot Delete an Object of One to Many Relationship Programmatically

I'm building a SwiftUI app with SwiftData where the start page is a list of Trip objects and the DetailView will be a map with Waypoint objects that belong to that Trip. This is a one Trip to many Waypoints relationship. I have simplified the code…
JohnSF
  • 3,736
  • 3
  • 36
  • 72