struct
Dictionary
<
Key
:
Hashable
,
Value
>
Inheritance |
CollectionType, DebugPrintable, DictionaryLiteralConvertible, Printable, Reflectable, SequenceType, _CollectionType, _SequenceType, _Sequence_Type
View Protocol Hierarchy →
|
---|---|
Associated Types |
Type alias inferred.
Type alias inferred. |
Import |
|
Initializers
Create an empty dictionary.
Declaration
init
()
Create an instance initialized with elements
.
Declaration
init
(
dictionaryLiteral
elements
: (
Key
,
Value
)...)
Create a dictionary with at least the given number of
elements worth of storage. The actual capacity will be the
smallest power of 2 that's >= minimumCapacity
.
Declaration
init
(
minimumCapacity
:
Int
)
Instance Variables
A textual representation of self
, suitable for debugging.
Declaration
var
debugDescription
:
String
{
get
}
The collection's "past the end" position.
endIndex
is not a valid argument to subscript
, and is always
reachable from startIndex
by zero or more applications of
successor()
.
Complexity: amortized O(1) if self
does not wrap a bridged
NSDictionary
, O(N) otherwise.
Declaration
var
endIndex
:
DictionaryIndex
<
Key
,
Value
>
{
get
}
A collection containing just the keys of self
Keys appear in the same order as they occur as the .0
member
of key-value pairs in self
. Each key in the result has a
unique value.
Declaration
var
keys
:
LazyForwardCollection
<
MapCollectionView
<
[
Key
:
Value
],
Key
>
>
{
get
}
The position of the first element in a non-empty dictionary.
Identical to endIndex
in an empty dictionary
Complexity: amortized O(1) if self
does not wrap a bridged
NSDictionary
, O(N) otherwise.
Declaration
var
startIndex
:
DictionaryIndex
<
Key
,
Value
>
{
get
}
A collection containing just the values of self
Values appear in the same order as they occur as the .1
member
of key-value pairs in self
.
Declaration
var
values
:
LazyForwardCollection
<
MapCollectionView
<
[
Key
:
Value
],
Value
>
>
{
get
}
Subscripts
Declaration
subscript
(
key
:
Key
) -
>
Value
?
Declaration
subscript
(
position
:
DictionaryIndex
<
Key
,
Value
>
) -
>
(
Key
,
Value
) {
get
}
Instance Methods
Return a generator over the (key, value) pairs.
Complexity: O(1)
Declaration
func
generate
() -
>
DictionaryGenerator
<
Key
,
Value
>
Returns the Index
for the given key, or nil
if the key is not
present in the dictionary.
Declaration
func
indexForKey
(
key
:
Key
) -
>
DictionaryIndex
<
Key
,
Value
>
?
Remove all elements.
Postcondition: capacity == 0
if keepCapacity
is false
, otherwise
the capacity will not be decreased.
Invalidates all indices with respect to self
.
keepCapacity If true
, the operation preserves the
storage capacity that the collection has, otherwise the underlying
storage is released. The default is false
.
Complexity: O(count
).
Declaration
mutating
func
removeAll
(
keepCapacity
:
Bool
=
default
)
Remove the key-value pair at index i
Invalidates all indices with respect to self
.
Complexity: O(count
).
Declaration
mutating
func
removeAtIndex
(
index
:
DictionaryIndex
<
Key
,
Value
>
)
Remove a given key and the associated value from the dictionary.
Returns the value that was removed, or nil
if the key was not present
in the dictionary.
Declaration
mutating
func
removeValueForKey
(
key
:
Key
) -
>
Value
?
Update the value stored in the dictionary for the given key, or, if they key does not exist, add a new key-value pair to the dictionary.
Returns the value that was replaced, or nil
if a new key-value pair
was added.
Declaration
mutating
func
updateValue
(
value
:
Value
,
forKey
key
:
Key
) -
>
Value
?
A hash-based mapping from
Key
toValue
instances. Also a collection of key-value pairs with no defined ordering.