Relative Content

Tag Archive for swiftswiftdataswift-data-relationship

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 that db and am having problems modifying it.

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 (the “index” person). I’ve settled on a model of having each person defining their nuclear family (parents, siblings, children, and spouse(s)), in addition to their relation to the index. This would allow the tree to be drawn (when I get that far) by traversing the relationships, and gives an easy way for the user to verify things. It seems necessary to do this way because I don’t just need to know Person B is the aunt of Index, I need to know how – Person B is sister of Person A who is father to index, etc.

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 relationship of Model, or because of how the models are used.

A way to populate Picker and then use this data to populate another data model with relationship

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 from those previously saved and fills out the rest of the data. The issue that I’m having, is that my app crashes when I try to save a model (probably because I’m setting the relationship wrong).

@Attriute(.preserveValueOnDeletion) in swiftData

what is the use of @Attriute(.preserveValueOnDeletion) and what is the use of this option in swiftData? the documentation just says that it preserves the value of the particular property even after deleting that object in the persistent history….but couldn’t actually find its use any where in the internet!