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

# leadSurrogate(_:)

Returns the high-surrogate code unit of the surrogate pair representing
the specified Unicode scalar.

```
static func leadSurrogate(_ x: Unicode.Scalar) -> UTF16.CodeUnit
```

## Parameters

`x`

A Unicode scalar value. `x` must be represented by a
surrogate pair when encoded in UTF-16. To check whether `x` is
represented by a surrogate pair, use `UTF16.width(x) == 2`.

## Return Value

The leading surrogate code unit of `x` when encoded in UTF-16.

## Discussion

Because a Unicode scalar value can require up to 21 bits to store its
value, some Unicode scalars are represented in UTF-16 by a pair of
16-bit code units. The first and second code units of the pair,
designated *leading* and *trailing* surrogates, make up a *surrogate
pair*.

```
let apple: Unicode.Scalar = "🍎"
print(UTF16.leadSurrogate(apple))
// Prints "55356"
```

---

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)