---
title: String.UnicodeScalarView
framework: swift
role: symbol
role_heading: Structure
path: swift/string/unicodescalarview
---

# String.UnicodeScalarView

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

## Declaration

```swift
@frozen struct UnicodeScalarView
```

## Overview

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 "

## Topics

### Instance Properties

- [customPlaygroundQuickLook](swift/string/unicodescalarview/customplaygroundquicklook.md)

### Instance Methods

- [isTriviallyIdentical(to:)](swift/string/unicodescalarview/istriviallyidentical(to:).md)

### Default Implementations

- [BidirectionalCollection Implementations](swift/string/unicodescalarview/bidirectionalcollection-implementations.md)
- [Collection Implementations](swift/string/unicodescalarview/collection-implementations.md)
- [CustomDebugStringConvertible Implementations](swift/string/unicodescalarview/customdebugstringconvertible-implementations.md)
- [CustomReflectable Implementations](swift/string/unicodescalarview/customreflectable-implementations.md)
- [CustomStringConvertible Implementations](swift/string/unicodescalarview/customstringconvertible-implementations.md)
- [RangeReplaceableCollection Implementations](swift/string/unicodescalarview/rangereplaceablecollection-implementations.md)
- [Sequence Implementations](swift/string/unicodescalarview/sequence-implementations.md)

## Relationships

### Conforms To

- [BidirectionalCollection](swift/bidirectionalcollection.md)
- [Collection](swift/collection.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Escapable](swift/escapable.md)
- [RangeReplaceableCollection](swift/rangereplaceablecollection.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)

## See Also

### Related String Types

- [Substring](swift/substring.md)
- [StringProtocol](swift/stringprotocol.md)
- [String.Index](swift/string/index.md)
- [String.UTF16View](swift/string/utf16view.md)
- [String.UTF8View](swift/string/utf8view.md)
- [String.Iterator](swift/string/iterator.md)
- [String.Encoding](swift/string/encoding.md)
