Learn Courses My Dashboard

Trying to create instance of ExerciseSet for an Exercise with Core Data

I am building an app to create a workout by selecting multiple exercises from a preset list with core data. I am getting the following error:

“Value of type ‘UUID’ has no member ‘addToExerciseSets’” on e.addToExerciseSets(newExerciseSet)

Exercise and ExerciseSet are separate Core Data entities with a relationship between them. The user can select multiple exercises from a list, I then want the user to hit “Add” and create an instance of ExerciseSet for each selected exercises, respectively.

import SwiftUI

    struct ExerciseSelectorView: View {
        @Environment(\.managedObjectContext) var viewContext
        @Environment(\.dismiss) var dismiss
        @FetchRequest(sortDescriptors: []) var exercises: 
    FetchedResults<Exercise>

@State var selectedItems = Set<UUID>()

var body: some View {
    NavigationView {
        
        List(selection: $selectedItems) {
            ForEach(exercises) { exercise in
                Text("\(exercise.exercisename)")
                
            }
            
        }.navigationBarTitle(Text("Selected \(selectedItems.count) rows"))
        
    }
}

func createExerciseSet() {
    
    for e in selectedItems {
        let newExerciseSet = ExerciseSet(context: viewContext)
        //newExerciseSet.exercise = e
        newExerciseSet.dateCompleted = Date()
        newExerciseSet.id = UUID()
        e.addToExerciseSets(newExerciseSet) // This is where error occurs            
        try? viewContext.save()
        dismiss()
    }
}

struct ExerciseSelectorView_Previews: PreviewProvider {
    static var previews: some View {
        ExerciseSelectorView()
    }
}

This is the Exercise Class

   extension Exercise {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Exercise> {
    return NSFetchRequest<Exercise>(entityName: "Exercise")
}

@NSManaged public var exercisename: String
@NSManaged public var musclegroup: String
@NSManaged public var id: UUID?
@NSManaged public var exerciseSet: ExerciseSet?

    }

    extension Exercise : Identifiable {

    }

    extension Exercise {

@objc(addExerciseSetsObject:)
@NSManaged public func addToExerciseSets(_ value: ExerciseSet)

@objc(removeExerciseSetsObject:)
@NSManaged public func removeFromExerciseSets(_ value: ExerciseSet)

@objc(addExerciseSets:)
@NSManaged public func addToExerciseSets(_ values: NSSet)

@objc(removeExerciseSets:)
@NSManaged public func removeFromExerciseSets(_ values: NSSet)

    }

Any help would be greatly appreciated! Thanks!