<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UnkeyedEncodingContainer/encode(contentsOf:)-36ny",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s24UnkeyedEncodingContainerP6encode10contentsOfyqd___tKSTRd__s5UInt8V7ElementRtd__lF"
  },
  "title" : "encode(contentsOf:)"
}
-->

# encode(contentsOf:)

Encodes the elements of the given sequence.

```
mutating func encode<T>(contentsOf sequence: T) throws where T : Sequence, T.Element == UInt8
```

## Parameters

`sequence`

The sequences whose contents to encode.

## Discussion> throws: An error if any of the contained values throws an error.

---

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)