Dictionary Types
Dictionaries have the form {K: V}
, where K
is the type of the key, and V
is the type of the value. For example, a dictionary with Int
keys and Bool
values has type {Int: Bool}
.
Dictionary types are covariant in their key and value types. For example, [Int: String]
is a subtype of [AnyStruct: String]
and also a subtype of [Int: AnyStruct]
. This is safe because dictionaries are value types and not reference types.
Last updated