Accesses the code unit at the given position.
SDK
- Xcode 7.1+
Framework
- Swift Standard Library
Declaration
Parameters
positionA valid index of the view.
positionmust be less than the view’s end index.
Discussion
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"