Instance Method


Saves the provided object to the HealthKit store.


- (void)saveObject:(HKObject *)object withCompletion:(void (^)(BOOL success, NSError *error))completion;



The HealthKit object to be saved. This object can be any concrete subclass of the HKObject class (any of the HKCategorySample, HKQuantitySample, HKCorrelation, or HKWorkout classes).


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


A Boolean value. This parameter contains YES if the object was successfully saved to the HealthKit store; otherwise, NO.


An error object. If an error occurred, this object contains information about the error; otherwise, it is set to nil.


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 HKErrorAuthorizationNotDetermined error. If your app has been denied permission to save the object’s data type, it fails with an HKErrorAuthorizationDenied error. Saving an object with the same unique identifier as an object already in the HealthKit store fails with an HKErrorInvalidArgument error.

In iOS 9.0 and later, saving an object to the HealthKit store sets the object’s sourceRevision property to a HKSourceRevision instance representing the saving app. On earlier versions of iOS, saving an object sets the source property to a 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 property. If the sample was saved using an earlier version of iOS, the source revision’s version is set to nil.

See Also

Working with HealthKit Objects

- deleteObject:withCompletion:

Deletes the specified object from the HealthKit store.

- deleteObjects:withCompletion:

Deletes the specified objects from the HealthKit store.

- deleteObjectsOfType:predicate:withCompletion:

Deletes objects saved by this application that match the provided type and predicate.

- earliestPermittedSampleDate

Returns the earliest date permitted for samples.

- saveObjects:withCompletion:

Saves an array of objects to the HealthKit store.