GTKeyValueCompliant

public protocol GTKeyValueCompliant

A protocol that allows to work with key-value data in a convenient way.

The protocol defines an associated type called ValueType, which makes it possible (for the protocol) to be used with any type of data. Additionally, that makes this protocol a reusable component that allows other entities to provide key-value pair based functionality hassle-free and without caring about the implementation details.

A protocol extension implements the defined methods and there is no need for custom implementation of them.

This protocol uses the GTKeyvalueCompliantStorage class as the custom, intermediate type that protects the actual data storage from direct access.

  • An associated type that enables GTKeyValueCompliant protocol to be used with any type of data.

    Declaration

    Swift

    associatedtype ValueType
  • The data storage object.

    Declaration

    Swift

    var storage: GTKeyValueCompliantStorage<ValueType> { get }
  • add(value:forKey:) Extension method

    Add the given value to storage using the given key.

    Declaration

    Swift

    public mutating func add(value: ValueType, forKey key: String)

    Parameters

    value

    The value to add to storage. Its type should match the ValueType type.

    key

    The key to pair with the given value.

  • add(multipleValues:) Extension method

    Assign the given collection of values to storage.

    Declaration

    Swift

    mutating public func add(multipleValues: [String : ValueType])

    Parameters

    multipleValues

    A [String: ValueType] dictionary of keys and values to add to storage, where ValueType the data type to use.

  • value(forKey:) Extension method

    Get the value for the given key.

    Declaration

    Swift

    public func value(forKey key: String) -> ValueType?

    Parameters

    key

    The key for the value that is searched.

    Return Value

    The found value as a ValueType, or nil no value is found in the values collection for the given key, where ValueType the data type specified in the ValueType associated type.

  • getStorageValues() Extension method

    It returns all values currently kept in storage property.

    Declaration

    Swift

    public func getStorageValues() -> [String : ValueType]
  • totalItems() Extension method

    It returns the total number of items in storage.

    Declaration

    Swift

    public func totalItems() -> Int

    Return Value

    An Int value regarding the total number of values.