<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.4 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIContext/writeHEIFRepresentation(of:to:format:colorSpace:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIContext(im)writeHEIFRepresentationOfImage:toURL:format:colorSpace:options:error:"
  },
  "title" : "writeHEIFRepresentation(of:to:format:colorSpace:options:)"
}
-->

# writeHEIFRepresentation(of:to:format:colorSpace:options:)

Renders the image and exports the resulting image data as a file in HEIF format.

```
func writeHEIFRepresentation(of image: CIImage, to url: URL, format: CIFormat, colorSpace: CGColorSpace, options: [CIImageRepresentationOption : Any] = [:]) throws
```

## Parameters

`image`

The image object to render.

`url`

The file URL at which to write the output HEIF file.

`format`

The pixel format for the output image.

`colorSpace`

The color space in which to render the output image. This color space must conform to either the <doc://com.apple.documentation/documentation/CoreGraphics/CGColorSpaceModel/rgb> or <doc://com.apple.documentation/documentation/CoreGraphics/CGColorSpaceModel/monochrome> model and must be compatible with the specified pixel format.

`options`

A dictionary with additional options for export.

## Discussion

To render an image for export, the image’s contents must not be empty and its [`extent`](/documentation/CoreImage/CIImage/extent) dimensions must be finite. To export after applying a filter whose output has infinite extent, see the [`clampedToExtent()`](/documentation/CoreImage/CIImage/clampedToExtent()) method.

In Objective-C `writeHEIFRepresentationOfImage` returns `true` if the file export succeeded. If `false`, examine the `errorPtr` parameter for possible failure reasons.

---

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)