Learn Courses My Dashboard

Select multiple items from a list saved in core data and adding those items in different core data entity with Xcode / SwiftUI

I am trying to make an app where the user can select multiple exercises from a list saved in core data to build a workout that is then saved in core data. I think of this as similar to the Recipe app, but being able to select ingredients from a preset list rather than typing them in. This way, the user will be able to track their progress with each individual exercise.

I have created a core data model with 3 entities - Exercise, ExerciseSet, and Workout. Exercise and ExerciseSet are related such that an ExerciseSet will consist of an Exercise chosen from that list and the number of reps. ExerciseSet and Workout have a relationship such that a Workout consists of multiple ExerciseSets.

So far, I have set up the data model and loaded in a list of exercises to the Exercise entity. Next, I want the user to create a workout by selecting multiple exercises from the list stored in core data. I want to save each exercise to an ExerciseSet and have the user input reps, weight, etc. I then want to add these ExerciseSets to a Workout and save that into Core Data. Does this data model make sense?

What would be the best way to do the next step of adding an exercise to an exercise set? I want the user to be able to view a list of exercises, select multiple, hit “Add”, and generate ExerciseSets that allow input for the users reps/weight. Then I want to save all of the ExerciseSets to a single workout for that day. I’ve tried to use a tableview and a multiple selection picker to save these into an exercise set but haven’t been successful.

I’ve tried a lot of things so far with no success and would greatly appreciate any feedback or suggestions!! Thanks!!