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: 

@State var selectedItems = Set<UUID>()

var body: some View {
    NavigationView {
        List(selection: $selectedItems) {
            ForEach(exercises) { exercise in
        }.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()

struct ExerciseSelectorView_Previews: PreviewProvider {
    static var previews: some View {

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 {

@NSManaged public func addToExerciseSets(_ value: ExerciseSet)

@NSManaged public func removeFromExerciseSets(_ value: ExerciseSet)

@NSManaged public func addToExerciseSets(_ values: NSSet)

@NSManaged public func removeFromExerciseSets(_ values: NSSet)


Any help would be greatly appreciated! Thanks!