One Logo Pool Ball
Foundation · IOS API REFERENCE

AttributedString.Runs

struct · iOS 15.0+ · SDK 27.1

struct Runs

An iterable view into segments of the attributed string, each of which indicates where a run of identical attributes begins or ends.

Members (10)

get · iOS 15.0+

startIndex

TypeScript
get startIndex(): AttributedString_Runs_Index
Swift declaration
var startIndex: AttributedString.Runs.Index { get }

The position of the first element in a nonempty collection. If the collection is empty, `startIndex` is equal to `endIndex`.

get · iOS 15.0+

description

TypeScript
get description(): string
Swift declaration
var description: String { get }

A textual representation of this instance. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(describing:)` initializer. This initializer works with any type, and uses the custom `description` property for types that conform to `CustomStringConvertible`: struct Point: CustomStringConvertible { let x: Int, y: Int var description: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(describing: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `description` property.

method · iOS 15.0+

index

TypeScript
indexAfter(i: AttributedString_Runs_Index): AttributedString_Runs_Index
Swift declaration
func index(after i: AttributedString.Runs.Index) -> AttributedString.Runs.Index

Returns the position immediately after the given index. The successor of an index must be well defined. For an index `i` into a collection `c`, calling `c.index(after: i)` returns the same index every time. - Parameter i: A valid index of the collection. `i` must be less than `endIndex`. - Returns: The index value immediately after `i`.

method · iOS 15.0+

index

TypeScript
indexBefore(i: AttributedString_Runs_Index): AttributedString_Runs_Index
Swift declaration
func index(before i: AttributedString.Runs.Index) -> AttributedString.Runs.Index

Returns the position immediately before the given index. - Parameter i: A valid index of the collection. `i` must be greater than `startIndex`. - Returns: The index value immediately before `i`.

method · iOS 15.0+

index

TypeScript
indexOffsetByLimitedBy(i: AttributedString_Runs_Index, distance: number, limit: AttributedString_Runs_Index): (AttributedString_Runs_Index) | null
Swift declaration
func index(_ i: AttributedString.Runs.Index, offsetBy distance: Int, limitedBy limit: AttributedString.Runs.Index) -> AttributedString.Runs.Index?

Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index. The following example obtains an index advanced four positions from a string's starting index and then prints the character at that position. The operation doesn't require going beyond the limiting `s.endIndex` value, so it succeeds. let s = "Swift" if let i = s.index(s.startIndex, offsetBy: 4, limitedBy: s.endIndex) { print(s[i]) } // Prints "t" The next example attempts to retrieve an index six positions from `s.startIndex` but fails, because that distance is beyond the index passed as `limit`. let j = s.index(s.startIndex, offsetBy: 6, limitedBy: s.endIndex) print(j) // Prints "nil" The value passed as `distance` must not offset `i` beyond the bounds of the collection, unless the index passed as `limit` prevents offsetting beyond those bounds. - Parameters: - i: A valid index of the collection. - distance: The distance to offset `i`. `distance` must not be negative unless the collection conforms to the `BidirectionalCollection` protocol. - limit: A valid index of the collection to use as a limit. If `distance > 0`, a limit that is less than `i` has no effect. Likewise, if `distance < 0`, a limit that is greater than `i` has no effect. - Returns: An index offset by `distance` from the index `i`, unless that index would be beyond `limit` in the direction of movement. In that case, the method returns `nil`. - Complexity: O(1) if the collection conforms to `RandomAccessCollection`; otherwise, O(*k*), where *k* is the absolute value of `distance`.

method · iOS 15.0+

index

TypeScript
indexOffsetBy(i: AttributedString_Runs_Index, distance: number): AttributedString_Runs_Index
Swift declaration
func index(_ i: AttributedString.Runs.Index, offsetBy distance: Int) -> AttributedString.Runs.Index

Returns an index that is the specified distance from the given index. The following example obtains an index advanced four positions from a string's starting index and then prints the character at that position. let s = "Swift" let i = s.index(s.startIndex, offsetBy: 4) print(s[i]) // Prints "t" The value passed as `distance` must not offset `i` beyond the bounds of the collection. - Parameters: - i: A valid index of the collection. - distance: The distance to offset `i`. `distance` must not be negative unless the collection conforms to the `BidirectionalCollection` protocol. - Returns: An index offset by `distance` from the index `i`. If `distance` is positive, this is the same value as the result of `distance` calls to `index(after:)`. If `distance` is negative, this is the same value as the result of `abs(distance)` calls to `index(before:)`. - Complexity: O(1) if the collection conforms to `RandomAccessCollection`; otherwise, O(*k*), where *k* is the absolute value of `distance`.

method · iOS 15.0+

distance

TypeScript
distance(start: AttributedString_Runs_Index, end: AttributedString_Runs_Index): number
Swift declaration
func distance(from start: AttributedString.Runs.Index, to end: AttributedString.Runs.Index) -> Int

Returns the distance between two indices. Unless the collection conforms to the `BidirectionalCollection` protocol, `start` must be less than or equal to `end`. - Parameters: - start: A valid index of the collection. - end: Another valid index of the collection. If `end` is equal to `start`, the result is zero. - Returns: The distance between `start` and `end`. The result can be negative only if the collection conforms to the `BidirectionalCollection` protocol. - Complexity: O(1) if the collection conforms to `RandomAccessCollection`; otherwise, O(*k*), where *k* is the resulting distance.

get · iOS 15.0+

endIndex

TypeScript
get endIndex(): AttributedString_Runs_Index
Swift declaration
var endIndex: AttributedString.Runs.Index { get }

The collection's "past the end" position---that is, the position one greater than the last valid subscript argument. When you need a range that includes the last element of a collection, use the half-open range operator (`..<`) with `endIndex`. The `..<` operator creates a range that doesn't include the upper bound, so it's always safe to use with `endIndex`. For example: let numbers = [10, 20, 30, 40, 50] if let index = numbers.firstIndex(of: 30) { print(numbers[index ..< numbers.endIndex]) } // Prints "[30, 40, 50]" If the collection is empty, `endIndex` is equal to `startIndex`.

subscript · iOS 15.0+

subscript

TypeScript
subscript(position: AttributedString_Index): AttributedString_Runs_Run
Swift declaration
subscript(position: AttributedString.Index) -> AttributedString.Runs.Run { get }
subscript · iOS 15.0+

subscript

TypeScript
subscript44362(position: AttributedString_Runs_Index): AttributedString_Runs_Run
Swift declaration
subscript(position: AttributedString.Runs.Index) -> AttributedString.Runs.Run { get }

Accesses the element at the specified position. The following example accesses an element of an array through its subscript to print its value: var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"] print(streets[1]) // Prints "Bryant" You can subscript a collection with any valid index other than the collection's end index. The end index refers to the position one past the last element of a collection, so it doesn't correspond with an element. - Parameter position: The position of the element to access. `position` must be a valid index of the collection that is not equal to the `endIndex` property. - Complexity: O(1)

Skipped declarations

10 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

AttributedString.Runs.subscript(_:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

AttributedString.Runs.subscript(_:)

Passing a Swift type itself is not supported.

AttributedString.Runs.subscript(_:_:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

AttributedString.Runs.subscript(_:_:)

Passing a Swift type itself is not supported.

AttributedString.Runs.subscript(_:_:_:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

AttributedString.Runs.subscript(_:_:_:)

Passing a Swift type itself is not supported.

AttributedString.Runs.subscript(_:_:_:_:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

AttributedString.Runs.subscript(_:_:_:_:)

Passing a Swift type itself is not supported.

AttributedString.Runs.subscript(_:_:_:_:_:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

AttributedString.Runs.subscript(_:_:_:_:_:)

Passing a Swift type itself is not supported.

All Foundation types →