<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKHealthStore/save(_:withCompletion:)-47iwb",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKHealthStore(im)saveObjects:withCompletion:"
  },
  "title" : "save(_:withCompletion:)"
}
-->

# save(_:withCompletion:)

Saves an array of objects to the HealthKit store.

```
func save(_ objects: [HKObject], withCompletion completion: @escaping @Sendable (Bool, (any Error)?) -> Void)
```

## Parameters

`objects`

An array containing concrete subclasses of the  [`HKObject`](/documentation/HealthKit/HKObject) class (any of the [`HKCategorySample`](/documentation/HealthKit/HKCategorySample), [`HKQuantitySample`](/documentation/HealthKit/HKQuantitySample), [`HKCorrelation`](/documentation/HealthKit/HKCorrelation), or [`HKWorkout`](/documentation/HealthKit/HKWorkout) classes).

`completion`

A block that this method calls as soon as the save operation is complete. This block is passed the following parameters:

- success: A Boolean value. This parameter contains <doc://com.apple.documentation/documentation/Swift/true> if the objects were successfully saved to the HealthKit store; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.
- error: An error object. If an error occurred, this object contains information about the error; otherwise, it is set to `nil`.

## Discussion

This method operates asynchronously. As soon as the save operation is finished, it calls the completion block on a background queue.

If your app has not requested permission to share the object’s data type, the method fails with an [`HKError.Code.errorAuthorizationNotDetermined`](/documentation/HealthKit/HKError/Code/errorAuthorizationNotDetermined) error. If your app has been denied permission to save the object’s data type, it fails with an [`HKError.Code.errorAuthorizationDenied`](/documentation/HealthKit/HKError/Code/errorAuthorizationDenied) error. Saving an object with the same unique identifier as an object already in the HealthKit store fails with an [`HKError.Code.errorInvalidArgument`](/documentation/HealthKit/HKError/Code/errorInvalidArgument) error. When saving multiple objects, if any object cannot be saved, none of them are saved.

In iOS 9.0 and later, saving an object to the HealthKit store sets the object’s [`sourceRevision`](/documentation/HealthKit/HKObject/sourceRevision) property to a [`HKSourceRevision`](/documentation/HealthKit/HKSourceRevision) instance representing the saving app. On earlier versions of iOS, saving an object sets the [`source`](/documentation/HealthKit/HKObject/source) property to a [`HKSource`](/documentation/HealthKit/HKSource) instance instead. In both cases, these values are available only after the object is retrieved from the HealthKit store. The original object is not changed.

All samples retrieved by iOS 9.0 and later are given a valid [`sourceRevision`](/documentation/HealthKit/HKObject/sourceRevision) property. If the sample was saved using an earlier version of iOS, the source revision’s version is set to `nil`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)