Values
A view of a dictionary’s values.
@frozen struct Values
A view of a dictionary’s values.
@frozen struct Values
where Key:Hashable
import Swift
@frozen struct Dictionary<Key, Value> where Key : Hashable
A collection whose elements are key-value pairs.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
init(dictionaryLiteral elements: (Key, Value)...)
Creates a dictionary initialized with a dictionary literal.
var capacity: Int { get }
The total number of key-value pairs that the dictionary can contain without allocating new storage.
var count: Int { get }
The number of key-value pairs in the dictionary.
var customMirror: Mirror { get }
A mirror that reflects the dictionary.
var debugDescription: String { get }
A string that represents the contents of the dictionary, suitable for debugging.
var description: String { get }
A string that represents the contents of the dictionary.
var endIndex: Dictionary<Key, Value>.Index { get }
The dictionary’s “past the end” position—that is, the position one greater than the last valid subscript argument.
var isEmpty: Bool { get }
A Boolean value that indicates whether the dictionary is empty.
var keys: Dictionary<Key, Value>.Keys { get }
A collection containing just the keys of the dictionary.
var startIndex: Dictionary<Key, Value>.Index { get }
The position of the first element in a nonempty dictionary.
var values: Dictionary<Key, Value>.Values { get set }
A collection containing just the values of the dictionary.
subscript(key: Key) -> Value? { get set }
Accesses the value associated with the given key for reading and writing.
subscript(position: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Element { get }
Accesses the key-value pair at the specified position.
subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value { get set }
Accesses the value with the given key, falling back to the given default value if the key isn’t found.
func compactMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> Dictionary<Key, T>
Returns a new dictionary containing only the key-value pairs that have non-nil
values as the result of transformation by the given closure.
func filter(_ isIncluded: (Dictionary<Key, Value>.Element) throws -> Bool) rethrows -> [Key : Value]
Returns a new dictionary containing the key-value pairs of the dictionary that satisfy the given predicate.
func formIndex(after i: inout Dictionary<Key, Value>.Index)
func index(after i: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Index
func index(forKey key: Key) -> Dictionary<Key, Value>.Index?
Returns the index for the given key.
func makeIterator() -> Dictionary<Key, Value>.Iterator
Returns an iterator over the dictionary’s key-value pairs.
func mapValues<T>(_ transform: (Value) throws -> T) rethrows -> Dictionary<Key, T>
Returns a new dictionary containing the keys of this dictionary with the values transformed by the given closure.
mutating func merge(_ other: [Key : Value], uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows
Merges the given dictionary into this dictionary, using a combining closure to determine the value for any duplicate keys.
mutating func merge<S>(_ other: S, uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows where S : Sequence, S.Element == (Key, Value)
Merges the key-value pairs in the given sequence into the dictionary, using a combining closure to determine the value for any duplicate keys.
func merging(_ other: [Key : Value], uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows -> [Key : Value]
Creates a dictionary by merging the given dictionary into this dictionary, using a combining closure to determine the value for duplicate keys.
func merging<S>(_ other: S, uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows -> [Key : Value] where S : Sequence, S.Element == (Key, Value)
Creates a dictionary by merging key-value pairs in a sequence into the dictionary, using a combining closure to determine the value for duplicate keys.
mutating func popFirst() -> Dictionary<Key, Value>.Element?
Removes and returns the first key-value pair of the dictionary if the dictionary isn’t empty.
@discardableResult mutating func remove(at index: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Element
Removes and returns the key-value pair at the specified index.
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
Removes all key-value pairs from the dictionary.
@discardableResult mutating func removeValue(forKey key: Key) -> Value?
Removes the given key and its associated value from the dictionary.
mutating func reserveCapacity(_ minimumCapacity: Int)
Reserves enough space to store the specified number of key-value pairs.
@discardableResult mutating func updateValue(_ value: Value, forKey key: Key) -> Value?
Updates the value stored in the dictionary for the given key, or adds a new key-value pair if the key does not exist.
@frozen struct Index
The position of a key-value pair in a dictionary.
@frozen struct Iterator
An iterator over the members of a Dictionary<Key, Value>
.
@frozen struct Keys
A view of a dictionary’s keys.
typealias SubSequence = Slice<Dictionary<Key, Value>>
protocol Collection<Element> : Sequence
A sequence whose elements can be traversed multiple times, nondestructively, and accessed by an indexed subscript.
protocol MutableCollection<Element> : Collection where Self.SubSequence : MutableCollection
A collection that supports subscript assignment.
protocol Sequence<Element>
A type that provides sequential, iterated access to its elements.
var count: Int { get }
The number of values in the dictionary.
var debugDescription: String { get }
var description: String { get }
var endIndex: Dictionary<Key, Value>.Index { get }
var isEmpty: Bool { get }
var startIndex: Dictionary<Key, Value>.Index { get }
subscript(position: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Values.Element { get set }
func formIndex(after i: inout Dictionary<Key, Value>.Index)
func index(after i: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Index
func makeIterator() -> Dictionary<Key, Value>.Values.Iterator
mutating func swapAt(_ i: Dictionary<Key, Value>.Index, _ j: Dictionary<Key, Value>.Index)
@frozen struct Iterator
typealias Element = Value
var first: Self.Element? { get }
The first element of the collection.
var indices: DefaultIndices<Self> { get }
The indices that are valid for subscripting the collection, in ascending order.
var lazy: LazySequence<Self> { get }
A sequence containing the same elements as this sequence, but on which some operations, such as map
and filter
, are implemented lazily.
var underestimatedCount: Int { get }
A value less than or equal to the number of elements in the collection.
func allSatisfy(_ predicate: (Self.Element) throws -> Bool) rethrows -> Bool
Returns a Boolean value indicating whether every element of a sequence satisfies a given predicate.
func compactMap<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult]
Returns an array containing the non-nil
results of calling the given transformation with each element of this sequence.
func contains(_ element: Self.Element) -> Bool
Returns a Boolean value indicating whether the sequence contains the given element.
func contains(where predicate: (Self.Element) throws -> Bool) rethrows -> Bool
Returns a Boolean value indicating whether the sequence contains an element that satisfies the given predicate.
func count<E>(where predicate: (Self.Element) throws(E) -> Bool) throws(E) -> Int where E : Error
Returns the number of elements in the sequence that satisfy the given predicate.
func distance(from start: Self.Index, to end: Self.Index) -> Int
Returns the distance between two indices.
func drop(while predicate: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence
Returns a subsequence by skipping elements while predicate
returns true
and returning the remaining elements.
func dropFirst(_ k: Int = 1) -> Self.SubSequence
Returns a subsequence containing all but the given number of initial elements.
func dropLast(_ k: Int = 1) -> Self.SubSequence
Returns a subsequence containing all but the specified number of final elements.
func elementsEqual<OtherSequence>(_ other: OtherSequence) -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.
func elementsEqual<OtherSequence>(_ other: OtherSequence, by areEquivalent: (Self.Element, OtherSequence.Element) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence
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 enumerated() -> EnumeratedSequence<Self>
Returns a sequence of pairs (n, x), where n represents a consecutive integer starting at zero and x represents an element of the sequence.
func filter(_ isIncluded: (Self.Element) throws -> Bool) rethrows -> [Self.Element]
Returns an array containing, in order, the elements of the sequence that satisfy the given predicate.
func first(where predicate: (Self.Element) throws -> Bool) rethrows -> Self.Element?
Returns the first element of the sequence that satisfies the given predicate.
func firstIndex(of element: Self.Element) -> Self.Index?
Returns the first index where the specified value appears in the collection.
func firstIndex(where predicate: (Self.Element) throws -> Bool) rethrows -> Self.Index?
Returns the first index in which an element of the collection satisfies the given predicate.
func flatMap<SegmentOfResult>(_ transform: (Self.Element) throws -> SegmentOfResult) rethrows -> [SegmentOfResult.Element] where SegmentOfResult : Sequence
Returns an array containing the concatenated results of calling the given transformation with each element of this sequence.
func forEach(_ body: (Self.Element) throws -> Void) rethrows
Calls the given closure on each element in the sequence in the same order as a for
-in
loop.
func formIndex(_ i: inout Self.Index, offsetBy distance: Int)
Offsets the given index by the specified distance.
func formIndex(_ i: inout Self.Index, offsetBy distance: Int, limitedBy limit: Self.Index) -> Bool
Offsets the given index by the specified distance, or so that it equals the given limiting index.
func index(_ i: Self.Index, offsetBy distance: Int) -> Self.Index
Returns an index that is the specified distance from the given index.
func index(_ i: Self.Index, offsetBy distance: Int, limitedBy limit: Self.Index) -> Self.Index?
Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index.
func indices(of element: Self.Element) -> RangeSet<Self.Index>
Returns the indices of all the elements that are equal to the given element.
func indices(where predicate: (Self.Element) throws -> Bool) rethrows -> RangeSet<Self.Index>
Returns the indices of all the elements that match the given predicate.
func joined() -> FlattenSequence<Self>
Returns the elements of this sequence of sequences, concatenated.
func joined<Separator>(separator: Separator) -> JoinedSequence<Self> where Separator : Sequence, Separator.Element == Self.Element.Element
Returns the concatenated elements of this sequence of sequences, inserting the given separator between each element.
func joined(separator: String = "") -> String
Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence) -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<
) to compare elements.
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence, by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.
func map<T, E>(_ transform: (Self.Element) throws(E) -> T) throws(E) -> [T] where E : Error
Returns an array containing the results of mapping the given closure over the sequence’s elements.
func map<T, E>(_ transform: (Self.Element) throws(E) -> T) throws(E) -> [T] where E : Error
Returns an array containing the results of mapping the given closure over the sequence’s elements.
@warn_unqualified_access func max() -> Self.Element?
Returns the maximum element in the sequence.
@warn_unqualified_access func max(by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Self.Element?
Returns the maximum element in the sequence, using the given predicate as the comparison between elements.
@warn_unqualified_access func min() -> Self.Element?
Returns the minimum element in the sequence.
@warn_unqualified_access func min(by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> Self.Element?
Returns the minimum element in the sequence, using the given predicate as the comparison between elements.
@discardableResult mutating func moveSubranges(_ subranges: RangeSet<Self.Index>, to insertionPoint: Self.Index) -> Range<Self.Index>
Moves the elements in the given subranges to just before the element at the specified index.
mutating func partition(by belongsInSecondPartition: (Self.Element) throws -> Bool) rethrows -> Self.Index
Reorders the elements of the collection such that all the elements that match the given predicate are after all the elements that don’t match.
func prefix(_ maxLength: Int) -> Self.SubSequence
Returns a subsequence, up to the specified maximum length, containing the initial elements of the collection.
func prefix(through position: Self.Index) -> Self.SubSequence
Returns a subsequence from the start of the collection through the specified position.
func prefix(upTo end: Self.Index) -> Self.SubSequence
Returns a subsequence from the start of the collection up to, but not including, the specified position.
func prefix(while predicate: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence
Returns a subsequence containing the initial elements until predicate
returns false
and skipping the remaining elements.
func randomElement() -> Self.Element?
Returns a random element of the collection.
func randomElement<T>(using generator: inout T) -> Self.Element? where T : RandomNumberGenerator
Returns a random element of the collection, using the given generator as a source for randomness.
func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Self.Element) throws -> Result) rethrows -> Result
Returns the result of combining the elements of the sequence using the given closure.
func reduce<Result>(into initialResult: Result, _ updateAccumulatingResult: (inout Result, Self.Element) throws -> ()) rethrows -> Result
Returns the result of combining the elements of the sequence using the given closure.
func removingSubranges(_ subranges: RangeSet<Self.Index>) -> DiscontiguousSlice<Self>
Returns a collection of the elements in this collection that are not represented by the given range set.
func reversed() -> [Self.Element]
Returns an array containing the elements of this sequence in reverse order.
func shuffled() -> [Self.Element]
Returns the elements of the sequence, shuffled.
func shuffled<T>(using generator: inout T) -> [Self.Element] where T : RandomNumberGenerator
Returns the elements of the sequence, shuffled using the given generator as a source for randomness.
func sorted() -> [Self.Element]
Returns the elements of the sequence, sorted.
func sorted(by areInIncreasingOrder: (Self.Element, Self.Element) throws -> Bool) rethrows -> [Self.Element]
Returns the elements of the sequence, sorted using the given predicate as the comparison between elements.
func split(maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true, whereSeparator isSeparator: (Self.Element) throws -> Bool) rethrows -> [Self.SubSequence]
Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.
func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) -> [ArraySlice<Self.Element>]
Returns the longest possible subsequences of the sequence, in order, around elements equal to the given element.
func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) -> [Self.SubSequence]
Returns the longest possible subsequences of the collection, in order, around elements equal to the given element.
func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix) -> Bool where PossiblePrefix : Sequence, Self.Element == PossiblePrefix.Element
Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.
func starts<PossiblePrefix>(with possiblePrefix: PossiblePrefix, by areEquivalent: (Self.Element, PossiblePrefix.Element) throws -> Bool) rethrows -> Bool where PossiblePrefix : Sequence
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 suffix(_ maxLength: Int) -> Self.SubSequence
Returns a subsequence, up to the given maximum length, containing the final elements of the collection.
func suffix(from start: Self.Index) -> Self.SubSequence
Returns a subsequence from the specified position to the end of the collection.
mutating func swapAt(_ i: Self.Index, _ j: Self.Index)
Exchanges the values at the specified indices of the collection.
mutating func withContiguousMutableStorageIfAvailable<R>(_ body: (inout UnsafeMutableBufferPointer<Self.Element>) throws -> R) rethrows -> R?
func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<Self.Element>) throws -> R) rethrows -> R?
func flatMap<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult]
func index(of element: Self.Element) -> Self.Index?
Returns the first index where the specified value appears in the collection.
protocol Sendable
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Escapable
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol CustomStringConvertible
A type with a customized textual representation.