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(multipleValues:)
Extension methodAssign 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 methodGet 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 theValueType
associated type. -
getStorageValues()
Extension method -
totalItems()
Extension methodIt 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.