StructureSwift5.9.0
Index
A position of a character or code unit in a string.
@frozen struct Index
Citizens in Swift
Conformances
protocol Comparable
A type that can be compared using the relational operators
<
,<=
,>=
, and>
.protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.
Members
init?(String
.Index, within: String.UnicodeScalarView) Creates an index in the given Unicode scalars view that corresponds exactly to the specified
UTF16View
position.init?(String
.Index, within: String.UTF8View) Creates an index in the given UTF-8 view that corresponds exactly to the specified
UTF16View
position.init?(String
.Index, within: String.UTF16View) Creates an index in the given UTF-16 view that corresponds exactly to the specified string position.
init?(String
.Index, within: String) Creates an index in the given string that corresponds exactly to the specified position.
init?<S>(String
.Index, within: S) Creates an index in the given string that corresponds exactly to the specified position.
init<S>(utf16Offset: Int, in: S
) Creates a new index at the specified UTF-16 code unit offset
static func < (String
.Index, String.Index) -> Bool static func == (String
.Index, String.Index) -> Bool func hash(into: inout Hasher
) Hashes the essential components of this value by feeding them into the given hasher.
func samePosition(in: String.UnicodeScalarView
) -> String.UnicodeScalarIndex? Returns the position in the given view of Unicode scalars that corresponds exactly to this index.
func samePosition(in: String.UTF8View
) -> String.UTF8View.Index? Returns the position in the given UTF-8 view that corresponds exactly to this index.
func samePosition(in: String.UTF16View
) -> String.UTF16View.Index? Returns the position in the given UTF-16 view that corresponds exactly to this index.
func samePosition(in: String
) -> String.Index? Returns the position in the given string that corresponds exactly to this index.
func utf16Offset<S>(in: S
) -> Int The UTF-16 code unit offset corresponding to this index.
init(encodedOffset: Int
) Creates a new index at the specified code unit offset.
var encodedOffset: Int
The offset into a string’s code units for this index.
Features
static func != (Self, Self
) -> Bool static func ... (Self
) -> PartialRangeFrom<Self> Returns a partial range extending upward from a lower bound.
static func ... (Self
) -> PartialRangeThrough<Self> Returns a partial range up to, and including, its upper bound.
static func ... (Self, Self
) -> ClosedRange<Self> Returns a closed range that contains both of its bounds.
static func ..< (Self
) -> PartialRangeUpTo<Self> Returns a partial range up to, but not including, its upper bound.
static func ..< (Self, Self
) -> Range<Self> Returns a half-open range that contains its lower bound but not its upper bound.