subscript(_:)
Accesses the code unit at the given position.
Declaration
subscript(idx: String.UTF16View.Index) -> UTF16.CodeUnit { get }Parameters
- idx:
A valid index of the view.
idxmust be less than the view’s end index.
Overview
The following example uses the subscript to print the value of a string’s first UTF-16 code unit.
let greeting = "Hello, friend!"
let i = greeting.utf16.startIndex
print("First character's UTF-16 code unit: \(greeting.utf16[i])")
// Prints "First character's UTF-16 code unit: 72"