---
title: "add(_:to:completion:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkhealthstore/add(_:to:completion:)"
---

# add(_:to:completion:)

Associates the provided samples with the specified workout.

## Declaration

```swift
func add(_ samples: [HKSample], to workout: HKWorkout, completion: @escaping @Sendable (Bool, (any Error)?) -> Void)
```

```swift
func addSamples(_ samples: [HKSample], to workout: HKWorkout) async throws
```

## Parameters

- `samples`: An array containing doc://com.apple.healthkit/documentation/HealthKit/HKCategorySample or doc://com.apple.healthkit/documentation/HealthKit/HKQuantitySample objects.
- `workout`: The workout object you are adding samples to.
- `completion`: A block that this method calls as soon as the add-samples operation is complete. This block is passed the following parameters:

## Mentioned in

Adding samples to a workout

## Discussion

Discussion This method operates asynchronously. As soon as the add-samples operation is finished, this method calls the completion block on a background queue. You must save the workout to the HealthKit store before you can add any samples to it. You can save the samples before calling this method, but doing so is not required. This method automatically saves any unsaved samples when it successfully adds them to the workout. To query for all the samples associated with a workout, add the workout to the query’s predicate. For example, the query’s predicateForObjects(from:) method creates a predicate object that matches only samples associated with the provided workout. For more information on workouts and associated samples, see HKWorkout.

## See Also

### Deprecated symbols

- [start(_:)](healthkit/hkhealthstore/start(_:).md)
- [end(_:)](healthkit/hkhealthstore/end(_:).md)
