<!--
{
  "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/Scalar/init(_:)-9eo1y",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s7UnicodeO6ScalarVyADSgs6UInt32Vcfc"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Creates a Unicode scalar with the specified numeric value.

```
init?(_ v: UInt32)
```

## Parameters

`v`

The Unicode code point to use for the scalar. The
initializer succeeds if `v` is a valid Unicode scalar value—that is,
if `v` is in the range `0...0xD7FF` or `0xE000...0x10FFFF`. If `v` is
an invalid Unicode scalar value, the result is `nil`.

## Discussion

For example, the following code sample creates a `Unicode.Scalar`
instance with a value of an emoji character:

```
let codepoint: UInt32 = 127881
let emoji = Unicode.Scalar(codepoint)
print(emoji!)
// Prints "🎉"
```

In case of an invalid input value, nil is returned.

```
let codepoint: UInt32 = extValue   // This might be an invalid value
if let emoji = Unicode.Scalar(codepoint) {
  print(emoji)
} else {
  // Do something else
}
```

---

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)