Search code examples
iosswifthealthkit

Is it possible to delete a HealthKit entry from my app?


I'm making an app with HealthKit and want to try to add a swipe to delete on my table view. I know there is a healthStore.delete option, but will this delete from the Health app and how would I know which HKSample to delete from HealthKit.


Solution

  • The HKSample class is an abstract class. Thus you should should never instantiate a HKSample object directly. Instead, you always work with one of the subclasses of HKSample (HKCategorySample, HKQuantitySample, HKCorrelation, or HKWorkout classes) where HKSampleClass1 would be one of the subclasses.

    healthStore.deleteObject(HKSampleClass1) { (success: Bool, error: NSError?) -> Void in { 
        if success () {
          //success in deletion 
        }
    }}