How can I read and display workout data similar to Apple Fitness?

I'm looking to display the workouts performed similar to what Apple Fitness displays. However, I want to get traditional strength training and functional strength training workouts particularly. I would also like to get the number of workouts performed within the week. I'm having issues reading the data and displaying it. Below is the code I'm using. I'm omitting the authorization method because I have that with other health variables I'm getting. Also, when I try to get the workoutActivity type to display, nothing is showing up. I've looked over apple's healthkit documentation but getting a big confused/lost as a beginner, particularly with the workout data. I've attached pictures as a reference on what I would like to accomplish


var selectedWorkoutQuery: HKQuery?
    @Published var muscleStrength: [HKWorkout] = [HKWorkout]()

func getStrengthTrainingWorkouts() {
        let date = Date()
        let startDate = Calendar.current.dateInterval(of: .weekOfYear, for: date)?.start
        let datePredicate = HKQuery.predicateForSamples(withStart: startDate, end: nil, options: .strictStartDate)

        let traditionalStrengthTrainingPredicate = HKQuery.predicateForWorkouts(with: .traditionalStrengthTraining)
        let functionalStrengthTrainingPredicate = HKQuery.predicateForWorkouts(with: .functionalStrengthTraining)

        let strengthCompound = NSCompoundPredicate(andPredicateWithSubpredicates: [datePredicate, traditionalStrengthTrainingPredicate, functionalStrengthTrainingPredicate])


        let selectedWorkoutQuery = HKSampleQuery(sampleType: HKWorkoutType.workoutType(), predicate: strengthCompound, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { strengthQuery, samples, error in
            
    guard let samples = samples else {
                fatalError("An error has occured \(error?.localizedDescription)")
            }
            

            DispatchQueue.main.async {
                
                if let workouts = samples as? [HKWorkout] {
                    
                    for workout in workouts {
                        self.muscleStrength.append(workout)
                    }
                }
            }
        }

        self.healthStore?.execute(selectedWorkoutQuery)

    }

Here is the view I would like to display the count and workouts but nothing is showing

struct MuscleView: View {
        @ObservedObject var healthStoreVM: HealthStoreViewModel
   
    var body: some View {
        List(healthStoreVM.muscleStrength, id: \.self) {
            workout in
            
            Text("\(workout.workoutActivityType.rawValue)")
        }

    }
}

Replies

muscleStrength should be an array of HKWorkout. Since it appears to remain initialized, I suggest adding a print("workouts: (String(describing: workouts))") above DispatchQueue.main.async to see what your HKSampleQuery is actually returning.