Structureswift 6.0.1Swift
Index
The position of a key-value pair in a dictionary.
@frozen struct Index
Dictionary has two subscripting interfaces:
Subscripting with a key, yielding an optional value:
v = d[k]!
Subscripting with an index, yielding a key-value pair:
(k, v) = d[i]
Other members in extension
View members
Hide members
This section is hidden by default because it contains too many (35) members.
Types
struct Iterator
An iterator over the members of a
Dictionary<Key, Value>
.struct Keys
A view of a dictionary’s keys.
struct Values
A view of a dictionary’s values.
Typealiases
Type members
init(dictionaryLiteral: (Key, Value)...
) Creates a dictionary initialized with a dictionary literal.
Instance members
var capacity: Int
The total number of key-value pairs that the dictionary can contain without allocating new storage.
var count: Int
The number of key-value pairs in the dictionary.
var customMirror: Mirror
A mirror that reflects the dictionary.
var debugDescription: String
A string that represents the contents of the dictionary, suitable for debugging.
var description: String
A string that represents the contents of the dictionary.
var endIndex: Dictionary<Key, Value>.Index
The dictionary’s “past the end” position—that is, the position one greater than the last valid subscript argument.
var isEmpty: Bool
A Boolean value that indicates whether the dictionary is empty.
var keys: Dictionary<Key, Value>.Keys
A collection containing just the keys of the dictionary.
var startIndex: Dictionary<Key, Value>.Index
The position of the first element in a nonempty dictionary.
var values: Dictionary<Key, Value>.Values
A collection containing just the values of the dictionary.
subscript(Key
) -> Value? Accesses the value associated with the given key for reading and writing.
subscript(Dictionary<Key, Value>.Index
) -> Dictionary<Key, Value>.Element Accesses the key-value pair at the specified position.
subscript(Key, default: @autoclosure () -> Value
) -> Value Accesses the value with the given key, falling back to the given default value if the key isn’t found.
func compactMapValues<T>((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((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: inout Dictionary<Key, Value>.Index
) func index(after: Dictionary<Key, Value>.Index
) -> Dictionary<Key, Value>.Index func index(forKey: 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>((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.
func merge([Key : Value], uniquingKeysWith: (Value, Value) throws -> Value
) rethrows Merges the given dictionary into this dictionary, using a combining closure to determine the value for any duplicate keys.
func merge<S>(S, uniquingKeysWith: (Value, Value) throws -> Value
) rethrows 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([Key : Value], uniquingKeysWith: (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>(S, uniquingKeysWith: (Value, Value) throws -> Value
) rethrows -> [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.
func popFirst(
) -> Dictionary<Key, Value>.Element? Removes and returns the first key-value pair of the dictionary if the dictionary isn’t empty.
func remove(at: Dictionary<Key, Value>.Index
) -> Dictionary<Key, Value>.Element Removes and returns the key-value pair at the specified index.
func removeAll(keepingCapacity: Bool
) Removes all key-value pairs from the dictionary.
func removeValue(forKey: Key
) -> Value? Removes the given key and its associated value from the dictionary.
func reserveCapacity(Int
) Reserves enough space to store the specified number of key-value pairs.
func updateValue(Value, forKey: 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.
Citizens in Swift
Conformances
Type members
static func < (lhs: Dictionary<Key, Value>.Index, rhs: Dictionary<Key, Value>.Index
) -> Bool static func == (lhs: Dictionary<Key, Value>.Index, rhs: Dictionary<Key, Value>.Index
) -> Bool
Instance members
Citizens in Swift
Conformances
Citizens in Swift
Conformances
protocol Comparable
A type that can be compared using the relational operators
<
,<=
,>=
, and>
.protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.
Type features
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.
static func ... (minimum: Self
) -> PartialRangeFrom<Self> Returns a partial range extending upward from a lower bound.
static func ... (maximum: Self
) -> PartialRangeThrough<Self> Returns a partial range up to, and including, its upper bound.
static func ... (minimum: Self, maximum: Self
) -> ClosedRange<Self> Returns a closed range that contains both of its bounds.
static func ..< (maximum: Self
) -> PartialRangeUpTo<Self> Returns a partial range up to, but not including, its upper bound.
static func ..< (minimum: Self, maximum: Self
) -> Range<Self> Returns a half-open range that contains its lower bound but not its upper bound.
static func <= (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.
static func > (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.
static func >= (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.