All Questions
Tagged with swiftdata swift-data-relationship
36
questions
0
votes
1
answer
55
views
SwiftData - How to build the multiple-to-multiple relationship between two data models?
Suppose I want to built Student and Course data models, and I want that each student is registered with multiple courses and each course contains multiple students. What should I do?
Here is what I ...
0
votes
1
answer
22
views
Swift Data Query only showing partial information?
I have an issue with Swift Data persistence on a sample app I'm working on.
I have two @Model classes set up, one for bets:
class Bet {
var id: UUID
var betDescription: String
var ...
-1
votes
0
answers
39
views
How do relationships not cause infinite loops?
So I'm still learning SwiftData and the one thing I cannot get my head around is how relationships don't cause infinite loops.
For example, using SwiftData, if you want to list all the films an actor ...
1
vote
1
answer
67
views
When pre-populating swiftdata, how to handle updates?
I’m pre-populating an app with an existing database that’s to be shipped with the app.
My approach is similar to the one outlined here and it works for an initial database, but now I need to update ...
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 ...
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 ...
0
votes
0
answers
34
views
Deleting a related model in cascade when parent is removed causes the app to crash
I understand that relating the Models should simplify data management in the app. I am currently developing an app that allows users to log refuel actions for cars added earlier. The goal is to delete ...
0
votes
1
answer
35
views
A way to populate Picker and then use this data to populate another data model with relationship [duplicate]
My problem is that I have two Models in my app - Car and Refuel. First one is to contain just a name of a car. User can have few cars. When a user refuels a tank and wants to log it, he selects a car ...
1
vote
1
answer
142
views
SwiftData does not retrieve my inverse one-to-many Relationship
Here is my models:
import SwiftData
@Model
final public class FirstModel {
let name: String
@Relationship(deleteRule: .cascade, inverse: \SecondModel.parent) var children = [SecondModel]()
...
2
votes
0
answers
144
views
SwiftData: Delete rule for many-to-many relationships
I have two SwiftData models, with a many-to-many relationship between them:
@Model
class Movie {
var name: String?
@Relationship(deleteRule: .nullify, inverse: \Actor.movies)
var actors: [...
0
votes
0
answers
69
views
SwiftData many-to-one relationships not being created until app restart
I'm trying to create a data structure in SwiftData that uses a many-to-one relationship, however, the parents list of children is not being appended to until the app is restarted.
I've modified the ...
1
vote
0
answers
120
views
Making undo/redo work with relationships: my mistake or SwiftData bug?
I'm trying to take advantage of SwiftData's automatic undo/redo support in a SwiftUI macOS app. I've overcome one of the wrinkles of getting it to work with relationships, but am stuck on another and ...
0
votes
0
answers
55
views
How to keep track of selected child items from an array?
New to SwiftData (and Core Data). In my app, I'd like to keep track of a selected item from a list of items, so it's available when the app is relaunched:
@Model
class Person {
var name: String
...
0
votes
0
answers
60
views
Xcode Preview crashes with swift data models with complex relationships
I use the following ModelContainer to have a preview DB, but it crash when I add more than one Model3 (after print "Container Done"). If I reduce model3 at one, It works correctly.
...