Subscript

subscript(_:default:)

Accesses the element with the given key, or the specified default value, if the dictionary doesn’t contain the given key.

Declaration

subscript(key: Dictionary<Key, Value>.Key, default defaultValue: @autoclosure () -> Dictionary<Key, Value>.Value) -> Dictionary<Key, Value>.Value { get set }

See Also

Accessing Keys and Values

subscript(Dictionary<Key, Value>.Key) -> Dictionary<Key, Value>.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.

var keys: Dictionary<Key, Value>.Keys

A collection containing just the keys of the dictionary.

var values: Dictionary<Key, Value>.Values

A collection containing just the values of the dictionary.

var first: (key: Key, value: Value)?

The first element of the collection.

func randomElement() -> (key: Key, value: Value)?

Returns a random element of the collection.

Beta
func randomElement<T>(using: inout T) -> (key: Key, value: Value)?

Returns a random element of the collection, using the given generator as a source for randomness.

Beta