String.UnicodeScalarView.Index

struct String.UnicodeScalarView.Index

A position in a string's UnicodeScalars view.

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 solid heart pictograph in the string's character view and then converts that to the same position in the Unicode scalars view:

let hearts = "Hearts <3 ♥︎ 💘"
let i = hearts.characters.index(of: "♥︎")!

let j = i.samePosition(in: hearts.unicodeScalars)
print(hearts.unicodeScalars.suffix(from: j))
// Prints "♥︎ 💘"
print(hearts.unicodeScalars[j].value)
// Prints "9829"
Inheritance Comparable, Equatable View Protocol Hierarchy →
Import import Swift

Instance Methods

func <(_:rhs:)

Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.

This function is the only requirement of the Comparable protocol. The remainder of the relational operator functions are implemented by the standard library for any type that conforms to Comparable.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func <(lhs: String.UnicodeScalarView.Index, rhs: String.UnicodeScalarView.Index) -> Bool
func ==(_:rhs:)

Returns a Boolean value indicating whether two values are equal.

Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

Parameters: lhs: A value to compare. rhs: Another value to compare.

Declaration

func ==(lhs: String.UnicodeScalarView.Index, rhs: String.UnicodeScalarView.Index) -> Bool