---
title: "encode(_:)"
framework: swift
role: symbol
role_heading: Type Method
path: "swift/unicode/utf16/encode(_:)"
---

# encode(_:)

Converts from encoding-independent to encoded representation, returning nil if the scalar can’t be represented in this encoding.

## Declaration

```swift
static func encode(_ source: Unicode.Scalar) -> Unicode.UTF16.EncodedScalar?
```
