Perform order-dependent operations common to all collections, as implemented for Dictionary.
Order Dependent Operations on Dictionary
Topics
Comparing Dictionaries
func elements Equal<Other Sequence>(Other Sequence, by: ((key: Key, value: Value), Other Sequence .Element) -> Bool) -> BoolReturns 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<Possible Prefix>(with: Possible Prefix, by: ((key: Key, value: Value), Possible Prefix .Element) -> Bool) -> BoolReturns 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 lexicographically Precedes<Other Sequence>(Other Sequence, by: ((key: Key, value: Value), (key: Key, value: Value)) -> Bool) -> BoolReturns 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 start Index: Dictionary<Key, Value>.IndexThe position of the first element in a nonempty dictionary.
var end Index: Dictionary<Key, Value>.IndexThe 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>.IndexReturns the position immediately after the given index.
func form Index(after: inout Dictionary<Key, Value>.Index)Replaces the given index with its successor.
func index(Dictionary<Key, Value>.Index, offset By: Int) -> Dictionary<Key, Value>.IndexReturns an index that is the specified distance from the given index.
func form Index(inout Dictionary<Key, Value>.Index, offset By: Int)Offsets the given index by the specified distance.
func index(Dictionary<Key, Value>.Index, offset By: Int, limited By: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Index?Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index.
func form Index(inout Dictionary<Key, Value>.Index, offset By: Int, limited By: Dictionary<Key, Value>.Index) -> BoolOffsets the given index by the specified distance, or so that it equals the given limiting index.
func distance(from: Dictionary<Key, Value>.Index, to: Dictionary<Key, Value>.Index) -> IntReturns the distance between two indices.
var indices: Default Indices<Dictionary<Key, Value>>The indices that are valid for subscripting the collection, in ascending order.
Selecting Elements
subscript(Range<Dictionary<Key, Value>.Index>) -> Slice<Dictionary<Key, Value>>Accesses a contiguous subrange of the collection’s elements.
subscript<R>(R) -> Slice<Dictionary<Key, Value>>Accesses the contiguous subrange of the collection’s elements specified by a range expression.
func prefix(Int) -> Slice<Dictionary<Key, Value>>Returns a subsequence, up to the specified maximum length, containing the initial elements of the collection.
func prefix(through: Dictionary<Key, Value>.Index) -> Slice<Dictionary<Key, Value>>Returns a subsequence from the start of the collection through the specified position.
func prefix(up To: Dictionary<Key, Value>.Index) -> Slice<Dictionary<Key, Value>>Returns a subsequence from the start of the collection up to, but not including, the specified position.
func prefix(while: ((key: Key, value: Value)) -> Bool) -> Slice<Dictionary<Key, Value>>Returns a subsequence containing the initial elements until predicate returns false and skipping the remaining elements.
func suffix(Int) -> Slice<Dictionary<Key, Value>>Returns a subsequence, up to the given maximum length, containing the final elements of the collection.
func suffix(from: Dictionary<Key, Value>.Index) -> Slice<Dictionary<Key, Value>>Returns a subsequence from the specified position to the end of the collection.
Excluding Elements
func drop First(Int) -> Slice<Dictionary<Key, Value>>Returns a subsequence containing all but the given number of initial elements.
func drop(while: ((key: Key, value: Value)) -> Bool) -> Slice<Dictionary<Key, Value>>Returns a subsequence by skipping elements while predicate returns true and returning the remaining elements.
func drop Last(Int) -> Slice<Dictionary<Key, Value>>Returns a subsequence containing all but the specified number of final elements.
func pop First() -> Dictionary<Key, Value>.Element?Removes and returns the first key-value pair of the dictionary if the dictionary isn’t empty.
Transforming a Dictionary's Elements
func split(max Splits: Int, omitting Empty Subsequences: Bool, where Separator: ((key: Key, value: Value)) -> Bool) -> [Slice<Dictionary<Key, Value>>]Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.
func reversed() -> [(key: Key, value: Value)]Returns an array containing the elements of this sequence in reverse order.
func with Contiguous Storage If Available<R>((Unsafe Buffer Pointer<(key: Key, value: Value)>) -> R) -> R?Call body(p), where p is a pointer to the collection’s contiguous storage. If no such storage exists, it is first created. If the collection does not support an internal representation in a form of contiguous storage, body is not called and nil is returned.