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

All 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 ...
HelloVictor2000's user avatar
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 ...
mg_berk's user avatar
  • 801
-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 ...
sam0701's user avatar
  • 11
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 ...
KidBaco's user avatar
  • 71
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 ...
leosebben's user avatar
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 ...
LighteningKid's user avatar
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 ...
Butee's user avatar
  • 1
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 ...
f16's user avatar
  • 649
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 ...
f16's user avatar
  • 649
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]() ...
OlivierM's user avatar
  • 3,082
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: [...
RRR's user avatar
  • 185
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 ...
DanWj's user avatar
  • 1
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 ...
Amar Sagoo's user avatar
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 ...
RRR's user avatar
  • 185
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. ...
FeroX's user avatar
  • 57

15 30 50 per page