<!--
{
  "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/String/UnicodeScalarView",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS17UnicodeScalarViewV"
  },
  "title" : "String.UnicodeScalarView"
}
-->

# String.UnicodeScalarView

A view of a string’s contents as a collection of Unicode scalar values.

```
@frozen struct UnicodeScalarView
```

## Overview

You can access a string’s view of Unicode scalar values by using its
`unicodeScalars` property. Unicode scalar values are the 21-bit codes
that are the basic unit of Unicode. Each scalar value is represented by
a `Unicode.Scalar` instance and is equivalent to a UTF-32 code unit.

```
let flowers = "Flowers 💐"
for v in flowers.unicodeScalars {
    print(v.value)
}
// 70
// 108
// 111
// 119
// 101
// 114
// 115
// 32
// 128144
```

Some characters that are visible in a string are made up of more than one
Unicode scalar value. In that case, a string’s `unicodeScalars` view
contains more elements than the string itself.

```
let flag = "🇵🇷"
for c in flag {
    print(c)
}
// 🇵🇷

for v in flag.unicodeScalars {
    print(v.value)
}
// 127477
// 127479
```

You can convert a `String.UnicodeScalarView` instance back into a string
using the `String` type’s `init(_:)` initializer.

```
let favemoji = "My favorite emoji is 🎉"
if let i = favemoji.unicodeScalars.firstIndex(where: { $0.value >= 128 }) {
    let asciiPrefix = String(favemoji.unicodeScalars[..<i])
    print(asciiPrefix)
}
// Prints "My favorite emoji is "
```

## Relationships

### Conforms To

[`Collection`](/documentation/Swift/Collection)

[`Sequence`](/documentation/Swift/Sequence)

[`Sendable`](/documentation/Swift/Sendable)

[`BidirectionalCollection`](/documentation/Swift/BidirectionalCollection)

[`Escapable`](/documentation/Swift/Escapable)

[`Copyable`](/documentation/Swift/Copyable)

[`CustomReflectable`](/documentation/Swift/CustomReflectable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`RangeReplaceableCollection`](/documentation/Swift/RangeReplaceableCollection)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

---

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)