---
title: HKSample
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hksample
---

# HKSample

A HealthKit sample represents a piece of data associated with a start and end time.

## Declaration

```swift
class HKSample
```

## Mentioned in

About the HealthKit framework Saving data to HealthKit Dividing a HealthKit workout into activities

## Overview

Overview The HKSample class is an abstract class. You should never instantiate a HKSample object directly. Instead, you always work with one of its concrete subclasses: HKCategorySample, HKQuantitySample, HKCorrelation, or HKWorkout classes. HealthKit samples are all immutable: You set the sample’s properties when you create it, and they cannot change. If the sample represents data over a duration, the start time must be earlier than the end time. If the sample represents data at a particular instant, the start and end times can be the same.

## Topics

### Accessing the Sample’s Data

- [startDate](healthkit/hksample/startdate.md)
- [endDate](healthkit/hksample/enddate.md)
- [hasUndeterminedDuration](healthkit/hksample/hasundeterminedduration.md)
- [sampleType](healthkit/hksample/sampletype.md)

### Specifying Sort Identifiers

- [HKSampleSortIdentifierStartDate](healthkit/hksamplesortidentifierstartdate.md)
- [HKSampleSortIdentifierEndDate](healthkit/hksamplesortidentifierenddate.md)

### Specifying Predicate Key Paths

- [HKPredicateKeyPathStartDate](healthkit/hkpredicatekeypathstartdate.md)
- [HKPredicateKeyPathEndDate](healthkit/hkpredicatekeypathenddate.md)

## Relationships

### Inherits From

- [HKObject](healthkit/hkobject.md)

### Inherited By

- [HKAudiogramSample](healthkit/hkaudiogramsample.md)
- [HKCategorySample](healthkit/hkcategorysample.md)
- [HKClinicalRecord](healthkit/hkclinicalrecord.md)
- [HKCorrelation](healthkit/hkcorrelation.md)
- [HKDocumentSample](healthkit/hkdocumentsample.md)
- [HKElectrocardiogram](healthkit/hkelectrocardiogram.md)
- [HKMedicationDoseEvent](healthkit/hkmedicationdoseevent.md)
- [HKQuantitySample](healthkit/hkquantitysample.md)
- [HKScoredAssessment](healthkit/hkscoredassessment.md)
- [HKSeriesSample](healthkit/hkseriessample.md)
- [HKStateOfMind](healthkit/hkstateofmind.md)
- [HKVerifiableClinicalRecord](healthkit/hkverifiableclinicalrecord.md)
- [HKVisionPrescription](healthkit/hkvisionprescription.md)
- [HKWorkout](healthkit/hkworkout.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Abstract superclasses

- [HKQuantitySample](healthkit/hkquantitysample.md)
- [HKObject](healthkit/hkobject.md)
