<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/order-dependent-operations-on-dictionary",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Order Dependent Operations on Dictionary"
}
-->

# Order Dependent Operations on Dictionary

Perform order-dependent operations common to all collections, as implemented for
`Dictionary`.

## Topics

### Comparing Dictionaries

[`func elementsEqual<OtherSequence>(OtherSequence, by: (Self.Element, OtherSequence.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/Dictionary/elementsEqual(_:by:))

Returns a Boolean value indicating whether this sequence and another
sequence contain equivalent elements in the same order, using the given
predicate as the equivalence test.

[`func starts<PossiblePrefix>(with: PossiblePrefix, by: (Self.Element, PossiblePrefix.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/Dictionary/starts(with:by:))

Returns a Boolean value indicating whether the initial elements of the
sequence are equivalent to the elements in another sequence, using
the given predicate as the equivalence test.

[`func lexicographicallyPrecedes<OtherSequence>(OtherSequence, by: (Self.Element, Self.Element) throws -> Bool) rethrows -> Bool`](/documentation/Swift/Dictionary/lexicographicallyPrecedes(_:by:))

Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the given
predicate to compare elements.

### Manipulating Indices

[`var startIndex: Dictionary<Key, Value>.Index`](/documentation/Swift/Dictionary/startIndex)

The position of the first element in a nonempty dictionary.

[`var endIndex: Dictionary<Key, Value>.Index`](/documentation/Swift/Dictionary/endIndex)

The dictionary’s “past the end” position—that is, the position one
greater than the last valid subscript argument.

[`func index(after: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Index`](/documentation/Swift/Dictionary/index(after:))

Returns the position immediately after the given index.

[`func formIndex(after: inout Dictionary<Key, Value>.Index)`](/documentation/Swift/Dictionary/formIndex(after:))

Replaces the given index with its successor.

[`func index(Self.Index, offsetBy: Int) -> Self.Index`](/documentation/Swift/Dictionary/index(_:offsetBy:))

Returns an index that is the specified distance from the given index.

[`func formIndex(inout Self.Index, offsetBy: Int)`](/documentation/Swift/Dictionary/formIndex(_:offsetBy:))

Offsets the given index by the specified distance.

[`func index(Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Self.Index?`](/documentation/Swift/Dictionary/index(_:offsetBy:limitedBy:))

Returns an index that is the specified distance from the given index,
unless that distance is beyond a given limiting index.

[`func formIndex(inout Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Bool`](/documentation/Swift/Dictionary/formIndex(_:offsetBy:limitedBy:))

Offsets the given index by the specified distance, or so that it equals
the given limiting index.

[`func distance(from: Self.Index, to: Self.Index) -> Int`](/documentation/Swift/Dictionary/distance(from:to:))

Returns the distance between two indices.

[`var indices: DefaultIndices<Self>`](/documentation/Swift/Dictionary/indices-swift.property)

The indices that are valid for subscripting the collection, in ascending
order.

### Selecting Elements

[`subscript(Range<Self.Index>) -> Slice<Self>`](/documentation/Swift/Dictionary/subscript(_:)-2ny9y)

Accesses a contiguous subrange of the collection’s elements.

[`subscript<R>(R) -> Self.SubSequence`](/documentation/Swift/Dictionary/subscript(_:)-4h7sk)

Accesses the contiguous subrange of the collection’s elements specified
by a range expression.

[`subscript(UnboundedRange) -> Self.SubSequence`](/documentation/Swift/Dictionary/subscript(_:)-4al9z)

[`func prefix(Int) -> Self.SubSequence`](/documentation/Swift/Dictionary/prefix(_:))

Returns a subsequence, up to the specified maximum length, containing
the initial elements of the collection.

[`func prefix(through: Self.Index) -> Self.SubSequence`](/documentation/Swift/Dictionary/prefix(through:))

Returns a subsequence from the start of the collection through the
specified position.

[`func prefix(upTo: Self.Index) -> Self.SubSequence`](/documentation/Swift/Dictionary/prefix(upTo:))

Returns a subsequence from the start of the collection up to, but not
including, the specified position.

[`func prefix(while: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence`](/documentation/Swift/Dictionary/prefix(while:))

Returns a subsequence containing the initial elements until `predicate`
returns `false` and skipping the remaining elements.

[`func suffix(Int) -> Self.SubSequence`](/documentation/Swift/Dictionary/suffix(_:))

Returns a subsequence, up to the given maximum length, containing the
final elements of the collection.

[`func suffix(from: Self.Index) -> Self.SubSequence`](/documentation/Swift/Dictionary/suffix(from:))

Returns a subsequence from the specified position to the end of the
collection.

### Excluding Elements

[`func dropFirst(Int) -> Self.SubSequence`](/documentation/Swift/Dictionary/dropFirst(_:))

Returns a subsequence containing all but the given number of initial
elements.

[`func drop(while: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence`](/documentation/Swift/Dictionary/drop(while:))

Returns a subsequence by skipping elements while `predicate` returns
`true` and returning the remaining elements.

[`func dropLast(Int) -> Self.SubSequence`](/documentation/Swift/Dictionary/dropLast(_:))

Returns a subsequence containing all but the specified number of final
elements.

[`func popFirst() -> Dictionary<Key, Value>.Element?`](/documentation/Swift/Dictionary/popFirst())

Removes and returns the first key-value pair of the dictionary if the
dictionary isn’t empty.

### Transforming a Dictionary’s Elements

[`func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Self.Element) throws -> Bool) rethrows -> [Self.SubSequence]`](/documentation/Swift/Dictionary/split(maxSplits:omittingEmptySubsequences:whereSeparator:))

Returns the longest possible subsequences of the collection, in order,
that don’t contain elements satisfying the given predicate.

[`func reversed() -> [Self.Element]`](/documentation/Swift/Dictionary/reversed())

Returns an array containing the elements of this sequence in reverse
order.

[`func withContiguousStorageIfAvailable<R>((UnsafeBufferPointer<Self.Element>) throws -> R) rethrows -> R?`](/documentation/Swift/Dictionary/withContiguousStorageIfAvailable(_:))

Executes a closure on the sequence’s contiguous storage.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)