Dictionary Fields and Functions
let length: Int // Declare a dictionary mapping strings to integers.
let numbers = {"fortyTwo": 42, "twentyThree": 23}
// Find the number of entries of the dictionary.
let length = numbers.length
// `length` is `2` fun insert(key: K, _ value: V): V? // Declare a dictionary mapping strings to integers.
let numbers = {"twentyThree": 23}
// Insert the key `"fortyTwo"` with the value `42` into the dictionary.
// The key did not previously exist in the dictionary,
// so the result is `nil`
//
let old = numbers.insert(key: "fortyTwo", 42)
// `old` is `nil`
// `numbers` is `{"twentyThree": 23, "fortyTwo": 42}`Last updated