DictionaryProtocol

public protocol DictionaryProtocol : Collection

Interface for Dictionary-like structures.

Associated Types

  • Key

    Key type.

    Declaration

    Swift

    associatedtype Key : Hashable
  • Value type.

    Declaration

    Swift

    associatedtype Value

Initializers

  • Create an empty DictionaryProtocol value.

    Declaration

    Swift

    init()
  • Creates an empty DictionaryProtocol-conforming type with preallocated space for at least the specified number of elements.

    Declaration

    Swift

    init(minimumCapacity: Int)

Subscripts

  • Declaration

    Swift

    subscript(key: Key) -> Value? { get set }

    Return Value

    Value for the given key, if present. Otherwise, nil.

  • Reserves the required amount of memory to store the given minimumCapacity of key-value pairs.

    Declaration

    Swift

    mutating func reserveCapacity(_ minimumCapacity: Int)
  • init(_:_:) Extension method

    Create a DictionaryProtocol with two parallel arrays.

    Note

    Useful for creating a dataset from x- and y-value arrays.

    Declaration

    Swift

    public init(_ xs: [Key], _ ys: [Value])
  • init(_:) Extension method

    Create a DictionaryProtocol-conforming type with a collection with dictionary-like elements.

    Declaration

    Swift

    public init<C>(_ collection: C) where C : Collection, C.Element == (key: Self.Key, value: Self.Value)

Instance Methods

  • merge(with:) Extension method

    Merge the contents of the given dictionary destructively into this one.

    Declaration

    Swift

    public mutating func merge(with dictionary: Self)
  • merged(with:) Extension method

    Declaration

    Swift

    public func merged(with dictionary: Self) -> Self

    Return Value

    A new Dictionary with the contents of the given dictionary merged self over those of self.

Available where Value: RangeReplaceableCollection

  • ensureValue(forKey:) Extension method

    Ensure that an RangeReplaceableCollection-conforming type value exists for the given key.

    Declaration

    Swift

    @inlinable
    public mutating func ensureValue(forKey key: Key)
  • safelyAppend(_:forKey:) Extension method

    Safely append the given value to the RangeReplaceableCollection-conforming type value for the given key.

    Declaration

    Swift

    @inlinable
    public mutating func safelyAppend(_ value: Value.Element, forKey key: Key)
  • Safely append the contents of an array to the Array-type value for the given key.

    Declaration

    Swift

    @inlinable
    public mutating func safelyAppend(contentsOf values: Value, forKey key: Key)

Available where Value: RangeReplaceableCollection, Value.Element: Equatable

  • Safely append value to the array value for a given key.

    If this value already exists in desired array, the new value will not be added.

    Declaration

    Swift

    @inlinable
    public mutating func safelyAndUniquelyAppend(_ value: Value.Element, forKey key: Key)

Available where Value: SetAlgebra

  • ensureValue(forKey:) Extension method

    Ensure that an SetAlgebra-conforming type value exists for the given key.

    Declaration

    Swift

    @inlinable
    public mutating func ensureValue(forKey key: Key)
  • safelyInsert(_:forKey:) Extension method

    Safely append the given value to the SetAlgebra-conforming type value for the given key.

    Declaration

    Swift

    @inlinable
    public mutating func safelyInsert(_ value: Value.Element, forKey key: Key)
  • safelyFormUnion(_:forKey:) Extension method

    Safely append the contents of an array to the SetAlgebra-conforming type value for the given key.

    Declaration

    Swift

    @inlinable
    public mutating func safelyFormUnion(_ other: Value, forKey key: Key)

Available where Value: DictionaryProtocol

  • ensureValue(forKey:) Extension method

    Ensure there is a value for a given key.

    Declaration

    Swift

    @inlinable
    public mutating func ensureValue(forKey key: Key)

Available where Value: DictionaryProtocol, Element == (Key, Value), Value.Element == (Value.Key, Value.Value)

  • merge(with:) Extension method

    Merge the contents of the given dictionary destructively into this one.

    Warning

    The value of a given key of the given dictionary will override that of this one.

    Declaration

    Swift

    public mutating func merge(with dictionary: Self)
  • merged(with:) Extension method

    Declaration

    Swift

    public mutating func merged(with dictionary: Self) -> Self

    Return Value

    A new Dictionary with the contents of the given dictionary merged self over those of self.