<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKVisionPrescription",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKVisionPrescription"
  },
  "title" : "HKVisionPrescription"
}
-->

# HKVisionPrescription

A sample that stores a vision prescription.

```
class HKVisionPrescription
```

## Overview

Use this class to create an image-only prescription. Here, you attach the prescription as an image or PDF to a simple sample. The sample contains only basic information about the prescription, such as the issue and expiration dates. To see the prescription data, people must view the attached image or PDF.

> Important:
> Some regions may require an image of the original prescription to validate the prescription record.

To create an image-only prescription, start by creating an [`HKVisionPrescription`](/documentation/HealthKit/HKVisionPrescription) sample object.

```swift
// Create a minimal prescription sample that just holds an image attachment.
let prescription = HKVisionPrescription(type: .glasses,
                                        dateIssued: Date(),
                                        expirationDate: nil,
                                        device: HKDevice.local(),
                                        metadata: nil)
```

Next, save the sample to the HealthKit store.

```swift
// Save the sample to the HealthKit store.
do {
    try await store.save(prescription)
} catch {
    // Handle the error here.
    fatalError("*** An error occurred while saving the prescription sample to the HealthKit store \(error.localizedDescription) ***")
}
```

Then, you can attach the image or PDF to the sample.

```swift
// Get the attachment store.
let attachmentStore = HKAttachmentStore(healthStore: store)

// Attach the image to the sample.
do {
    _ = try await attachmentStore.addAttachment(to: prescription,
                                                name: "Glasses Prescription",
                                                contentType: type,
                                                url: url)
} catch {
    // Handle the error.
    fatalError("*** An error occurred while attaching the image: \(error.localizedDescription) ***")
}
```

For more information about adding images or pdfs as attachments, see [`HKAttachmentStore`](/documentation/HealthKit/HKAttachmentStore). To create a vision prescription sample that contains the full data for the prescription, use [`HKGlassesPrescription`](/documentation/HealthKit/HKGlassesPrescription) or [`HKContactsPrescription`](/documentation/HealthKit/HKContactsPrescription) instead.

## Topics

### Creating vision prescription samples

[`convenience init(type: HKVisionPrescriptionType, dateIssued: Date, expirationDate: Date?, device: HKDevice?, metadata: [String : Any]?)`](/documentation/HealthKit/HKVisionPrescription/init(type:dateIssued:expirationDate:device:metadata:))

Creates a new vision prescription sample.

### Accessing the prescription data

[`var prescriptionType: HKVisionPrescriptionType`](/documentation/HealthKit/HKVisionPrescription/prescriptionType)

The type of vision prescription.

[`enum HKVisionPrescriptionType`](/documentation/HealthKit/HKVisionPrescriptionType)

The type of vision prescription, for example a prescription for glasses or for contacts.

[`var dateIssued: Date`](/documentation/HealthKit/HKVisionPrescription/dateIssued)

The date when the doctor issued the prescription.

[`var expirationDate: Date?`](/documentation/HealthKit/HKVisionPrescription/expirationDate)

The date when the prescription expires.

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CVarArg`](/documentation/Swift/CVarArg)

### Inherits From

[`HKSample`](/documentation/HealthKit/HKSample)

### Inherited By

[`HKContactsPrescription`](/documentation/HealthKit/HKContactsPrescription)

[`HKGlassesPrescription`](/documentation/HealthKit/HKGlassesPrescription)

---

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)