Instance Method

distance(to:)

Returns the distance from this value to the given value, expressed as a stride.

Declaration

func distance(to other: Int) -> Int

Parameters

other

The value to calculate the distance to.

Return Value

The distance from this value to other.

Discussion

For two values x and y, and a distance n = x.distance(to: y), x.advanced(by: n) == y.

Relationships

From Protocol

See Also

Infrequently Used Functionality

init()

Creates a new value equal to zero.

init(integerLiteral: Int)

Creates an instance initialized to the specified integer value.

typealias Int.IntegerLiteralType

A type that represents an integer literal.

func advanced(by: Int) -> Int

Returns a value that is offset the specified distance from this value.