String.CharacterView.Index

struct String.CharacterView.Index

A position in a string's CharacterView instance.

You can convert between indices of the different string views by using conversion initializers and the samePosition(in:) method overloads. The following example finds the index of the first space in the string's character view and then converts that to the same position in the UTF-8 view:

let hearts = "Hearts <3 ♥︎ 💘"
if let i = hearts.characters.index(of: " ") {
    let j = i.samePosition(in: hearts.utf8)
    print(Array(hearts.utf8.prefix(upTo: j)))
}
// Prints "[72, 101, 97, 114, 116, 115]"
Inheritance Comparable, CustomPlaygroundQuickLookable, Equatable View Protocol Hierarchy →
Import import Swift

Instance Variables

var customPlaygroundQuickLook: PlaygroundQuickLook

A custom playground Quick Look for this instance.

If this type has value semantics, the PlaygroundQuickLook instance should be unaffected by subsequent mutations.

Declaration

var customPlaygroundQuickLook: PlaygroundQuickLook { get }