---
title: "subscript(_:)"
framework: swift
role: symbol
role_heading: Instance Subscript
path: "swift/string/utf8view/subscript(_:)-6nubh"
---

# subscript(_:)

Accesses the code unit at the given position.

## Declaration

```swift
subscript(i: String.UTF8View.Index) -> UTF8.CodeUnit { get }
```

## Overview

Overview The following example uses the subscript to print the value of a string’s first UTF-8 code unit. let greeting = "Hello, friend!" let i = greeting.utf8.startIndex print("First character's UTF-8 code unit: \(greeting.utf8[i])") // Prints "First character's UTF-8 code unit: 72"
