<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVCaptionRegion/encode(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVCaptionRegion(im)encodeWithCoder:"
  },
  "title" : "encode(with:)"
}
-->

# encode(with:)

Encodes the region using the specified encoder.

```
func encode(with encoder: NSCoder)
```

## Parameters

`encoder`

An encoder instance to use.

## Discussion

This method throws an exception if the caption region’s [`size`](/documentation/AVFoundation/AVCaptionRegion/size) has different units for [`width`](/documentation/AVFoundation/AVCaptionSize/width) and [`height`](/documentation/AVFoundation/AVCaptionSize/height), or if the units are unrecognizeable.

---

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)