Dictionary

class Dictionary

A heterogeneous dictionary which stores associations between keys of the different types and values of the different types in a collection with no defined ordering. Each value is associated with a unique key, which acts as an identifier for that value within the dictionary. Unlike items in an array, items in a dictionary do not have a specified order. You use a dictionary when you need to look up values based on their identifier, in much the same way that a real-world dictionary is used to look up the definition for a particular word.

  • Number of key-value pairs in the dictionary.

    Declaration

    var count: Double { get }
  • An array containing the keys of the dictionary in an unspecified order.

    Declaration

    var keys: Array { get }
  • An array containing the values of the dictionary in an unspecified order.

    Declaration

    var values: Array { get }
  • true if the dictionary does not contain any key-value pairs, false otherwise.

    Declaration

    var isEmpty: Bool { get }
  • Compares two values for equality.

    The equals function is invoked using infix notation as in the following code snippet: lhs == rhs.

    Declaration

    func equals(_ lhs: Dictionary) -> Bool

    Parameters

    lhs

    A value.

    rhs

    Another value.

    Return Value

    true if the lhs and rhs are equal, false otherwise.

  • Returns a new dictionary where the value of key is updated to value.

    Declaration

    func updatingValue(_ value: Any, forKey key: Any) -> Dictionary

    Parameters

    value

    The new value.

    key

    A dictionary key.

    Return Value

    A new dictionary where the value of key is updated to value.