<!--
{
  "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/Unicode/UTF32/encode(_:into:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s7UnicodeO5UTF32O6encode_4intoyAB6ScalarV_ys6UInt32VXEtFZ"
  },
  "title" : "encode(_:into:)"
}
-->

# encode(_:into:)

Encodes a Unicode scalar as a UTF-32 code unit by calling the given
closure.

```
static func encode(_ input: Unicode.Scalar, into processCodeUnit: (Unicode.UTF32.CodeUnit) -> Void)
```

## Parameters

`input`

The Unicode scalar value to encode.

`processCodeUnit`

A closure that processes one code unit argument at a
time.

## Discussion

For example, like every Unicode scalar, the musical fermata symbol (“𝄐”)
can be represented in UTF-32 as a single code unit. The following code
encodes a fermata in UTF-32:

```
var codeUnit: UTF32.CodeUnit = 0
UTF32.encode("𝄐", into: { codeUnit = $0 })
print(codeUnit)
// Prints "119056"
```

---

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)